Solved

VB.Net - Check if Row Selected in DataGrid

Posted on 2014-01-31
2
8,388 Views
Last Modified: 2014-01-31
Good Day Experts!

I am having a little bit of trouble with my project.  I have a DataGrid that I would like to check if a row is selected.  

I use this code to get the selected row but I cannot figure out how to check if a row is selected:

Dim CodeGrid As String = Me.dgrdAccessorial.Rows(Me.dgrdAccessorial.CurrentRow.Index).Cells("Code").Value.ToString

Can you offer some hints of help?

Thanks,
jimbo99999
0
Comment
Question by:Jimbo99999
2 Comments
 
LVL 7

Assisted Solution

by:XGIS
XGIS earned 50 total points
ID: 39824582
Hello Jimbo,

Please check this code in relation to your implementation, including the display of the confirmation message.

' DataGridView Event 
Private Sub DataGridView1_SelectionChanged(..) 
   MsgBox("SelectionChanged: Current Row is " & DataGridView.CurrentRow.Index)
End Sub 

' First Row Button Event 
Private Sub FirstRow_Click(...)
   ' Force to first row
   DataGridView1.CurrentCell = DataGridView1.Rows(0).Cells(0)
   MsgBox("First Row Button Click: Current Row is  " & DataGridView.CurrentRow.Index) 
End Sub

Open in new window

0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 450 total points
ID: 39824596
To check whether or not a row is selected

If IsNothing(Me.dgrdAccessorial.CurrentRow) Then
   'No row selected
Else
   'Row selected
End If
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now