Click here to Skip to main content
13,191,400 members (81,594 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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
                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

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
Updated 15-Jan-13 23:54pm

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 |
Web03 | 2.8.171017.1 | Last Updated 16 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