Click here to Skip to main content
12,692,778 members (33,659 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
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..
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 17-Jan-13 23:37pm
Updated 18-Jan-13 7:27am
Kschuler35.2K
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()
Kschuler 18-Jan-13 12:31pm
   
Have you tried doing a .Insert instead of a .Add?
Rachna0309 18-Jan-13 23:05pm
   
Yes I have tried using INSERT too but it gives me same error "Column cannot be added because it is unfrozen and placed before a frozen column."...Code is below which I tried using Insert..

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.Insert(10, cmbCaste)

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Don't repost the same question 5 hours later. Show some freakin' patience.
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.170118.1 | Last Updated 18 Jan 2013
Copyright © CodeProject, 1999-2017
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