Datagridview select row and column

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2008
Posts: 4
Reputation: daniel50096230 is an unknown quantity at this point 
Solved Threads: 0
daniel50096230 daniel50096230 is offline Offline
Newbie Poster

Datagridview select row and column

 
0
  #1
Jan 9th, 2009
Hi,I has a problem here...

I has a datagridview and now I would like to determine that whether column1 in row 1 is selected by the user.What should I write to do so?



  1. Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
  2. If (DataGridView1.Rows(1).Cells(1).Selected) Then
  3. MessageBox.Show("")
  4. End If
  5. End Sub
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 710
Reputation: Teme64 will become famous soon enough Teme64 will become famous soon enough 
Solved Threads: 114
Teme64's Avatar
Teme64 Teme64 is offline Offline
Master Poster

Re: Datagridview select row and column

 
0
  #2
Jan 9th, 2009
In the DataGridView control indices start from 0, so I've used 0 instead of 1.

You can trap CellClick event handler
  1. Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
  2. '
  3. If e.ColumnIndex = 0 AndAlso e.RowIndex = 0 Then
  4. ' User clicked Col0 and Row0
  5. End If
  6.  
  7. End Sub
If you want to check selected cell outside any event
  1. Dim oCell As DataGridViewCell
  2. For Each oCell In DataGridView1.SelectedCells
  3. If oCell.ColumnIndex = 0 AndAlso oCell.RowIndex = 0 Then
  4. ' User has selected Col0 and Row0
  5. End If
  6. Next
HTH
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC