Click here to Skip to main content
12,943,528 members (50,418 online)
Rate this:
 
Please Sign up or sign in to 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 14-Jan-13 23:06pm
Updated 15-Jan-13 3:46am
Kschuler35.3K
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.
Teju MB 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)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,643
CHill60 2,970
Maciej Los 2,348
Jochen Arndt 1,900
ppolymorphe 1,765


Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 17 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