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 datagridview populated with several columns,out of which some columns I want to change from textbox cell to comboboxcell at runtime. I have written a piece of code which works perfectly fine but it takes time to load grid.Below is the code:
For Each row As DataGridViewRow In dgvUserDetails.Rows
            If row.Index < dgvUserDetails.Rows.Count - 1 Then
                Dim cmbprof As New DataGridViewComboBoxCell()
                dgvUserDetails.Rows(row.Index).Cells(8) = cmbprof
                sql = "Select Description from Category where Catgry = 5"
                If rs.State = 1 Then rs.Close()
                rs.Open(sql, MainCon, 1, 3)
                Do While Not rs.EOF
                    cmbprof.Items.Add(rs.Fields(0).Value)
                    rs.MoveNext()
                Loop
 
                sql = "Select Prof from datafile where Part_No = " & dgvUserDetails.Item("Baaga", row.Index).Value & " and SLNOINPART= " & dgvUserDetails.Item("emaaMk", row.Index).Value & ""
                If rs.State = 1 Then rs.Close()
                rs.Open(sql, MainCon, 1, 3)
                If Not rs.EOF Then
                    If Not IsDBNull(rs.Fields(0).Value) Then
                        gProf = rs.Fields(0).Value
                        cmbprof.DisplayMember = "Prof"
                        cmbprof.Value = gProf
                    End If
                End If
            End If
        Next
 

Now this code fills cmbprof for each row even though it has same values.If I declare cmbprof out of For loop,it gives me error "Cell provided already belongs to grid."Can any1 please help me to rectify this..My grid takes long time to load due to this.
Posted 15-Jan-13 22:21pm
Edited 15-Jan-13 23:54pm
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 470
1 Gihan Liyanage 317
2 ClimerChinna 182
3 vikinghunter 176
4 OriginalGriff 141
0 Sergey Alexandrovich Kryukov 8,653
1 OriginalGriff 7,132
2 CPallini 2,598
3 Richard MacCutchan 2,060
4 Abhinav S 1,808


Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 16 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