We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,397 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How to change textboxcell to comboboxcell in datagridview at runtime

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.

1
Contributor
0
Replies
2
Views
Rachna0309
Light Poster
36 posts since Nov 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0531 seconds using 2.65MB