When I select a cell in a datagrid I want the entire row to be selected. How do I do this?
Loading
When I select a cell in a datagrid I want the entire row to be selected. How do I do this?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Hirendra SisodiyaRank #258 · 9.8K reputationPosted Nov 26, 2009, 6:54 PM EST
thank you.
Lalit MRank #1,186 · 1.5K reputationPosted Nov 26, 2009, 7:02 PM EST
Private Sub DataGridView1_DataSourceChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.DataSourceChanged DataGridView1.ClearSelection() Dim dt As DataTable = CType(DataGridView1.DataSource, DataTable) Dim drs() As DataRow = dt.Select(DataGridView1.Columns(0).DataPropertyName & " = '" & TextBox1.Text & "'") If drs.Length > 0 Then DataGridView1.Rows(dt.Rows.IndexOf(drs(0))).Selected = True End If End Sub OR Private Sub mydatagridview_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles mydatagridview.MouseUp 'we will select first the entire row so that we can simply point the cell value to be displayed in the textboxes Dim hit As DataGridView.HitTestInfo = Me.mydatagridview.HitTest(e.X, e.Y) If hit.Type = DataGridViewHitTestType.Cell Then Me.mydatagridview.ClearSelection() Me.mydatagridview.Rows(hit.RowIndex).Selected = True Textbox1.Text = Me.mydatagridview.SelectedCells(0).Value Textbox2.Text= Me.mydatagridview.SelectedCells(1).Value 'do the rest End If End Subpaul daniel189 reputationPosted Dec 31, 2009, 3:43 AM EST
Refer this link
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_20826376.html
Thanks,
Paul daniel