Solved

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

Posted on 2011-03-23
1
812 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
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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