Solved

Vb.net Datagridview: is a cell selected?

Posted on 2012-03-31
8
851 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
Comment Utility
Handle the CellClick event of the datagridview
0
 

Author Comment

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

Expert Comment

by:nepaluz
Comment Utility
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
 

Author Comment

by:baabaa_nl
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 17

Expert Comment

by:nepaluz
Comment Utility
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
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
You were right, after adding the try catch block and ignoring the error, it was working perfectly. Good job.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

7 Experts available now in Live!

Get 1:1 Help Now