Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
I am populating datagridview with 9 columns through dataset. After this I add 4 comboboxes programatically. Now for the first time form loads, everything goes well. But if I change selected value in combobox from FORM,grid does not gets value and it shows error "Column cannot be added because it is unfrozen and placed before a frozen column."..In my datagridview ,columns 1 to 8 are frozen..Below is my code to add combobox in grid at runtime.
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()
 
It gives me error at line "dgvUserDetails.Columns.Add(cmbCaste)" second time when I change value in comboxbox of FORM.Please help me its urgent.
Posted 17-Jan-13 17:56pm

1 solution

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

Solution 1

Please help me its urgent.
 
Why is everything everyone does in India "urgent"??
 
Sorry, but we're all volunteers here answering question in our own spare time, not when you demand.
 
If it was that urgent, you should have been reading the documentation on the DGV and its Columns collection class. In there, you would have noticed that instead of Add, you can use an Insert method to put the column anywhere you want into the Columns collection and avoid the error you got.
  Permalink  
Comments
Adam R Harris at 18-Jan-13 12:18pm
   
LMFAO - excellent, my 5
Rachna0309 at 18-Jan-13 12:22pm
   
I tried using Insert too....But it shows same error...
Dave Kreskowiak at 18-Jan-13 12:31pm
   
Without seeing the Insert code, it's impossible to help you out.
Rachna0309 at 18-Jan-13 23:06pm
   
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)
 

I have tried using the above code...But it gives me same error...
Dave Kreskowiak at 19-Jan-13 0:40am
   
This code has nothing to do with insert and is exactly the same as above.
Rachna0309 at 19-Jan-13 1:11am
   
I solved it myself..Anyways Thanks

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

  Print Answers RSS
0 OriginalGriff 6,656
1 Sergey Alexandrovich Kryukov 6,490
2 CPallini 5,310
3 George Jonsson 3,584
4 Gihan Liyanage 2,650


Advertise | Privacy | Mobile
Web04 | 2.8.140921.1 | Last Updated 18 Jan 2013
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