Solved

VB.Net - Check if Row Selected in DataGrid

Posted on 2014-01-31
2
9,789 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

717 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