Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Vb.net Datagridview: is a cell selected?

Posted on 2012-03-31
8
Medium Priority
?
883 Views
Last Modified: 2012-06-27
I am using vb.net,

In datagridview, i need a code that will check whether a cell has be selected or not on a datagridview.

Thanks in advance
0
Comment
Question by:baabaa_nl
  • 4
  • 4
8 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 37791193
Handle the CellClick event of the datagridview
0
 

Author Comment

by:baabaa_nl
ID: 37791196
I mean, i need to know if any cell in the gridview has focus?
0
 
LVL 17

Expert Comment

by:nepaluz
ID: 37791234
the CellClick event will tell you which cell has focus in a datagridview.you probably did not phrase your question correctly .... but whenever a cell is click (not event in edit mode!), then the cell click event will know about it.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:baabaa_nl
ID: 37791239
Ok , now what if not a single cell is on focus on the gridview, are there any method or properties that would return any boolean values.
0
 
LVL 17

Expert Comment

by:nepaluz
ID: 37791256
Not sure I understand your second question. If you want to know what cell was last de-selected, I do not think there is an in-built method forthis, but you can always implement a simple class wide string variable to hold this value and just set it whenever you select another cell.
0
 

Author Comment

by:baabaa_nl
ID: 37791268
hmmmm,

Well the reason why i asked you such a question was due to the following reason.

In my datagridview i have set the CellEndEdit Event. When the the cell is under the edit mode, and when i click on the other cells, the event works fine.

But when i am on an edit mode on a cell and when i click on the row header, i get a NullReferenceException. so due to that i am trying to check first if any cell has focus at that time.

Thanks in advance.
0
 
LVL 17

Accepted Solution

by:
nepaluz earned 2000 total points
ID: 37791280
That you get a null reference exception is proof that the EndEdit event has fired. You could simply wrap your routine in a try catch (and ignore the error), or set up a condition for filtering out the selection of a header row. Other than that, I would have to see the code you have in your EndEdit event (to ascertain why you get the error and what your code is trying to do) before I can suggest any work-arounds.
0
 

Author Closing Comment

by:baabaa_nl
ID: 37791307
You were right, after adding the try catch block and ignoring the error, it was working perfectly. Good job.
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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

916 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