Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this code below
VB
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
Updated 6-Oct-12 3:58am
v2

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?
 
Share this answer
 
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

VB
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
 
Share this answer
 
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
VB
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
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900