Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to add columns in datagridview after some already frozen columns. How can I add it?

I fill datagridview(columns 1 to 8) using dataset on a button click..then I use this dataset as datasource for datagridview. After this I freeze first 8 columns by setting frozen property to true. After this I have one method called "FillCombo" in which all combobox's are filled and are added to datagridview.
Below is the piece of code for filling one combo and then adding to datagridview. Likewise same for other columns is also same..
VB
sql = "Select Description from Category where Catgry = 1" 
If rs.State = 1 Then rs.Close() 
rs.Open(sql, MainCon, 1, 3) 
Do While Not rs.EOF 
   cmbCaste.Items.Add(rs.Fields(0).Value) 
   rs.MoveNext() 
Loop 
cmbCaste.HeaderText = "jaita" 
cmbCaste.Name = "Caste" 
dgvUserDetails.Columns.Add(cmbCaste) 
dgvUserDetails.Columns("Caste").DisplayIndex = 10 
rs.Close()
Posted
Updated 18-Jan-13 6:27am
v2
Comments
Kschuler 18-Jan-13 10:59am    
It all depends on how you are loading the grid. Could you post some of your code and let us know what you tried and why it isn't working? Include any error messages that you get as well.
martonthenagy 24-Aug-13 7:44am    
The exception tells what is the exact problem.
Allowed: Frozen, Frozen, Frozen, Unfrozen, Unfrozen
Not allowed: Frozen, Frozen, Unfrozen, Unfrozen, Frozen

If you add a column, it should became the last.
So if your grid contains frozen and unfrozen columns too, you can only add unfrozen column. After adding you can set its DisplayIndex, and after it you can set it to Frozen.

Maybe the DisplayIndex property takes effect place immediately, so you must set it up, before adding the column.
Rachna0309 18-Jan-13 11:18am    
http://www.codeproject.com/Questions/529878/Afterpluschangingplusvalueplusinpluscomboboxplusin
Refer this link..I have written this piece of code...
Kschuler 18-Jan-13 11:22am    
yeah...don't be lazy. If you really want help click the Improve Question link and add the code to your original question. Second, that code doesn't help us much at all. You're only adding the one column. How are you loading the other columns? When are you setting one or more columns to frozen?
Rachna0309 18-Jan-13 12:15pm    
I fill datagridview(columns 1 to 8) using dataset on a button click..then I use this dataset as datasource for datagridview..After this I freeze first 8 columns by setting frozen property to true..
After this I have one method called "FillCombo" in which all combobox's are filled and are added to datagridview...Below is the piece of code for filling one combo and then adding to datagridview. Likewise same for other columns is also same..


sql = "Select Description from Category where Catgry = 1"
If rs.State = 1 Then rs.Close()
rs.Open(sql, MainCon, 1, 3)
Do While Not rs.EOF
cmbCaste.Items.Add(rs.Fields(0).Value)
rs.MoveNext()
Loop
cmbCaste.HeaderText = "jaita"
cmbCaste.Name = "Caste"
dgvUserDetails.Columns.Add(cmbCaste)
dgvUserDetails.Columns("Caste").DisplayIndex = 10
rs.Close()

1 solution

Don't repost the same question 5 hours later. Show some freakin' patience.
 
Share this answer
 
Comments
Rachna0309 18-Jan-13 12:20pm    
I had to provide solution to my client so I re-posted it again...
Dave Kreskowiak 18-Jan-13 12:29pm    
Not our problem. Reposting the question doesn't get you an answer any faster. Chances are really good it gets you ignored.

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