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 which is populated with 8 columns also it is databound. Now my requirement is I need the last column say ABC As comboboxcolumn. But if in database, this ABC column has some value for a particular row, then that value should be displayed in that row's cell as selected value. Please help me to solve this.
 
- - - - UPDATE - - - - -
Dim cmbcaste As New DataGridViewComboBoxColumn()
cmbcaste.Name = "Caste"
cmbcaste.HeaderText = "Caste"
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 
dgvUserDetails.Columns.Add(cmbcaste) 
I have written the above code but it adds another combobox column and only fills combo.
Posted 14-Jan-13 23:06pm
Edited 15-Jan-13 3:46am
Kschuler32.8K
v2
Comments
Shanu2rick at 15-Jan-13 5:51am
   
Same as you get the values of the other columns!
Rachna0309 at 15-Jan-13 5:53am
   
Dim cmbcaste As New DataGridViewComboBoxColumn()
cmbcaste.Name = "Caste"
cmbcaste.HeaderText = "Caste"
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
dgvUserDetails.Columns.Add(cmbcaste)
 

I have written the above code but it adds another combobox column and only fills combo.
Teju MB at 17-Jan-13 23:31pm
   
Where you are writing these lines of code??
because of "dgvUserDetails.Columns.Add(cmbcaste) " it may add another combobox to your Grid, No need to specify this line, if you have already bound the comboBox to the Grid.

1 solution

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

Solution 1

try this...
 
textbox1.text = dgvUserDetails.CurrentRow.Cells("Caste").Value.ToString()
  Permalink  

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



Advertise | Privacy | Mobile
Web01 | 2.8.141022.2 | Last Updated 17 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