Solved

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

Posted on 2011-03-23
1
797 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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

728 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

13 Experts available now in Live!

Get 1:1 Help Now