Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
I have this code below
cmb.HeaderText = "Promoted To"
cmb.Name = "cmb"
cmb.MaxDropDownItems = 4
cmb.items.add("Class 2")   
cmb.items.add("Class 3")
DataGridView.Columns.Insert(4, cmb)
this code is at form load and each time i load the form, the DataGridViewComboBoxColumn is inserted at position 4.but i want the DataGridViewComboBoxColumn to be inserted once and if it already exit it should not be inserted again.
Posted 6-Oct-12 3:53am
Edited 6-Oct-12 3:58am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

if you want the combo to be inserted only the first time the pageloads u can put ur code inside Not IsPostback loop of page load
 
If Not IsPostBack
 
cmb.HeaderText = "Promoted To"
cmb.Name = "cmb"
cmb.MaxDropDownItems = 4
cmb.items.add("Class 2")
cmb.items.add("Class 3")
DataGridView.Columns.Insert(4, cmb)
 
End If
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

i have 7 columns so when the form is loaded for the first time, the number of columns become 8 because of the insertion of the cmb.
so i use this code to prevent further insertion of cmb
 If DataGridView.Columns.Count < 8 Then
                    Dim cmb As New DataGridViewComboBoxColumn()
                    cmb.HeaderText = "Promoted To"
                    cmb.Name = "cmb"
                    cmb.MaxDropDownItems = 4
                    DataGridView.Columns.Insert(4, cmb)
                End If
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This doesn't make sense. If you're "loading" the form more than once, you're creating a new instance of it which has no knowledge of any previous instance. This means that every instance should be creating it's combo column in position 4 every time.
 
Or am I missing something that you didn't explain in your post?
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.141022.2 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100