How do i get the selected value of a datagridview combobox column?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Beany
    New Member
    • Nov 2006
    • 173

    How do i get the selected value of a datagridview combobox column?

    Morning,

    i would like to know how i get the selected value of a datagridview combobox column?

    googling but no joy

    ta
  • Gopi
    New Member
    • Mar 2012
    • 5

    #2
    hi man
    do you want to know about selected row value from paricular column in datagridview and store that values into ur combobox ?
    Or get combobox values and load into datagridview in particular column? Can you send ur code or send ur problem clearly?
    anyway here is answer for first question
    'Here put ur DBconnection
    'I use con, cmd,dr, dt as object of sqlconnection,c ommand,
    'sqldatadapter, datatable you can as you declared object
    'example: design form with Two text boxes, one combobox in combobox you 'can store the Course of the student
    Code:
     In Grid Selection Changed Event you write this code
    dr = New SqlDataAdapter("Select * from student where Studentid = " &
    givenid & " ", con)
    dr.Fill(dt)
    If dt.Rows.Count > 0 Then
                    txtStudentid.Text = dt.Rows.Item(0).Item("Studentid")
                    txtFname.Text = dt.Rows.Item(0).Item("Fname")
                    ComboBox1.SelectedItem = dt.Rows.Item(0).Item("Course")
    End if
    'While you run the formload event you load combox values also
    'by same way use above code to select course from student table and 'assign it to combobox.
    'Then it run smartly

    Comment

    Working...