This post is continuation to the post which was posted by StatiX on Oct 23rd, 2007 regarding "Get The Selected row in DatagridView". Addition to this post i have a question.

The answer was given by manoshailu as follows:

Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
Dim i, j As Integer
i = DataGridView1.CurrentRow.Index
TextBox1.Text = DataGridView1.Item(0, i).Value
TextBox2.Text = DataGridView1.Item(1, i).Value
TextBox3.Text = DataGridView1.Item(2, i).Value
TextBox4.Text = DataGridView1.Item(3, i).Value
End Sub

This answer solved my problem but CANY ANYONE (manoshailu) TELL ME HOW TO ADD SIMILAR CODE FOR "Checkbox"? . I have check box in my form which returns a value "True" and "False" in SQL Database. When i select cell of datagrid the check box doesnt checks in as well as checks out accordingly with the value of datagrid.

My code are as follows:

Private Sub grvDesignationList_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grvDesignationList.CellClick
        Dim i As Integer
        i = grvDesignationList.CurrentRow.Index
        txtDesignationID.Text = grvDesignationList.Item(0, i).Value
        txtDesignationName.Text = grvDesignationList.Item(1, i).Value
        txtDesShortName.Text = grvDesignationList.Item(2, i).Value
        txtDesDescription.Text = grvDesignationList.Item(3, i).Value
        desDefaultCheckbox.CheckState = grvDesignationList.Item(4, i).Value
    End Sub

My Code above seems to be not working.
Please HELP!

regards,
tashiDuks

Edited 6 Years Ago by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

HI Everyone,

I have a form with datagrid. When i click the rows of data grid i can fill all the values in form controls except checkbox. My check box checked state seems to be not changing when i click on rows of the datagrid. I have a column in datagrid which returns the value "True and False" in database.

So can anyone tell me how to?

my Code are as follows:

Private Sub grvDesignationList_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grvDesignationList.CellClick
        Dim i As Integer
        i = grvDesignationList.CurrentRow.Index
        txtDesignationID.Text = grvDesignationList.Item(0, i).Value
        txtDesignationName.Text = grvDesignationList.Item(1, i).Value
        txtDesShortName.Text = grvDesignationList.Item(2, i).Value
        txtDesDescription.Text = grvDesignationList.Item(3, i).Value
        desDefaultCheckbox.CheckState = grvDesignationList.Item(4, i).Value

    End Sub

HI Everyone,

I have a form with datagrid. When i click the rows of data grid i can fill all the values in form controls except checkbox. My check box checked state seems to be not changing when i click on rows of the datagrid. I have a column in datagrid which returns the value "True and False" in database.

So can anyone tell me how to?

my Code are as follows:

Private Sub grvDesignationList_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grvDesignationList.CellClick
        Dim i As Integer
        i = grvDesignationList.CurrentRow.Index
        txtDesignationID.Text = grvDesignationList.Item(0, i).Value
        txtDesignationName.Text = grvDesignationList.Item(1, i).Value
        txtDesShortName.Text = grvDesignationList.Item(2, i).Value
        txtDesDescription.Text = grvDesignationList.Item(3, i).Value
        desDefaultCheckbox.CheckState = grvDesignationList.Item(4, i).Value

    End Sub

You can do this using e.Rows.FindControl("checkboxid"). store it as checkbox and change the check status to checked. After that u can use it with checkbox properties.

I'm glad you got it working. Please mark this thread as solved if you have found an answer to your question and good luck!

This article has been dead for over six months. Start a new discussion instead.