Solved

How to select datagridview row if a blank cell is  clicked?

Posted on 2011-03-23
1
842 Views
Last Modified: 2012-05-11
I have a datagridview that is populated from a SQL database table.The rows and columns show up properly. I am trying to capture the information from the row when a cell is selected in that row. I am using CellContentClick event and as long as I click on actual text in any cell the event fires and works as it should. However if I click on a blank cell or even on a blank area in a cell that has text, the event will not fire. Is there another cell click event I should use that will run regard whether I click on the actual text or not?

I am programming in VS2010 VB.NET.
0
Comment
Question by:laughslogan
[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
1 Comment
 
LVL 15

Accepted Solution

by:
David L. Hansen earned 50 total points
ID: 35202648
Been there!  So annoying, I know.  The answer is to use the CellClick event instead of the CellContentClick event.  It is so much better.  Also, you can get the row's data easily by using the following (NOTE: the big thing here is the DataBoundItem property...the example is just fluff).


Private Sub InvoiceButton_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles InvoiceButton.Click

    For Each row As DataGridViewRow In Me.DataGridView1.SelectedRows

        Dim cust As Customer = TryCast(row.DataBoundItem, Customer)
        If cust IsNot Nothing Then
            cust.SendInvoice()
        End If

    Next

End Sub

Open in new window

0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

623 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