VB.NET (Winforms) - DataGrid with Linq

I am working on a project.  I have two datagrids.  There is a datagrid on the left and right.  When I select datagrid on the left it will populate on the right.

I pretty much have it working.  I am using linq to populate both datagrid's.  I load the left and then based on the selection of the left I grab the ID and use linq to populate the right.

The issue I seem to be having is that when I'm clicking on the left nothing is happening.  I put a breakpoint in the code behind and the breakpoint isn't reached.

Any ideas?
LVL 2
CipherISAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Well without seeing any of the code and not knowing which event on the left DataGridView you are activating we can not tell what is happening. Please post the code you have and any other pertinent information.
CipherISAuthor Commented:
Here is the code.  It seems that when I click on the datagrid this doesn't fire at times.  My crystal reports piece works fine and other areas of code works fine just this part doesn't seem to work consistently.

Private Sub dgInvoices_CellContentClick(sender As Object, e As Windows.Forms.DataGridViewCellEventArgs) Handles dgInvoices.CellContentClick

        Dim id As String
        Dim x As Integer

        x = e.RowIndex

        id = Me.dgInvoices.Item(0, x).Value

        'Get Data from database
        Dim db As New InvoicePaymentsDataContext
        Dim qPayments = (From apayments In db.Payments
                 Where apayments.inv_id = id
                 Select apayments).ToList

        Me.dgPayments.DataSource = qPayments
        Me.dgPayments.Refresh()

    End Sub

Open in new window

Fernando SotoRetiredCommented:
I can not see any reason why this is not working, it looks fine. You state the following in your last post, "doesn't fire at times.", are you sure you are clicking on the center of the cell so that it detects the click event when it seems not to work?
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

CipherISAuthor Commented:
Yes.  I actually would prefer it would fire if I clicked on the row.  I changed the property on the grid to select the entire row.
Fernando SotoRetiredCommented:
And did that correct the issue?
CipherISAuthor Commented:
No, its not working like that.  When I tried to implement it that way then what happens is that I only get one row on the right grid instead of all the data.  Unsure why.
Fernando SotoRetiredCommented:
Try placing a breakpoint on this line of code, Me.dgPayments.DataSource = qPayments, and see how many elements are in the variable qPayments.
CipherISAuthor Commented:
I put a breakpoint at the beginning of the method and at times it doesn't reach it.  I could try that when I change the code.
Fernando SotoRetiredCommented:
What event handler did you move to, to select the row?
CipherISAuthor Commented:
Only two choices I see are

CellContentClick
SelectionChanged

I am currently using CellContentClick.  When I use SelectionChanged it only has one record in the left grid when there should be more.
CipherISAuthor Commented:
I was able to get it to work with CellClick.
CipherISAuthor Commented:
CellClick resolved all the issues.  I have selectionMode set to FullRowSelect.  The CellClick will fire no matter where I click on the grid.
Fernando SotoRetiredCommented:
Hi CipherIS;

I built a small project and used you code and it worked each and every time. Try using the event handler dgInvoices.RowHeaderMouseClick. and place your code in it. When you click on the Row Header it will select the complete row. To trigger this event click in the column where the right pointing triangle is in on the same row as the blue row selection is in.

GridViewControl Showing RowHeader

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.