Click here to Skip to main content
15,884,976 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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
Updated 15-Jan-13 3:46am
v2
Comments
Shanu2rick 15-Jan-13 5:51am    
Same as you get the values of the other columns!
Rachna0309 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.
The Doer 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

try this...

VB
textbox1.text = dgvUserDetails.CurrentRow.Cells("Caste").Value.ToString()
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900