Form with 2 datagrids

John Cassell

Well-known member
Joined
Mar 20, 2007
Messages
65
Programming Experience
Beginner
Hi,

Can someone tell me how to achieve the following pls...

I have a form which displays search results based on what the user is doing. Example he may enter 'UNITED' and press F2 which will load the form and display the 'Customers' datagridview. Alternatively he may enter 'A0123' and press F2 which will load the form and display the 'Jobs' datagrid view.

I have a couple of problems with how this is working:

1. If I need the form to load with the Jobs Datagridview, instead of simply writing searchform.show followed by SearchForm.TBL_JobsDataGridView.Show I, for some reason have to put it like this..

VB.NET:
SearchForm.Show()
            SearchForm.TBL_CustomersDataGridView.SendToBack()

Shouldn't I be able to display the Jobs datagrid instead of what seems like the opposite way around, i.e DON'T show the customer datagrid?

and

2. I need to be able to get the value of the cell in the first column of the row they are on and I have been able to get this by this code:
VB.NET:
TBL_CustomersDataGridView.CurrentRow.Cells(0).Value

What I need though is instead of saying 'show me the value of the cell in the CustomersDataGridView', I would like it to say 'Show me the value of the cell in the currently displayed Datagridview. Is this possible?

Thanks

John
 
First I want to make sure that I understand you correctly. Both of these controls are on the same form?
You may want to try putting each gridview in its own panel, or create a tab? This may not work for what your trying though.
As for your second part. Try looking at the .Focused property of the grid to see which one the user is looking at first.

Hope this helps.
 
Hi, thanks for the reply.

Yes, both of the controls are on the same form. Putting each one on it's own tab would work I think so thanks for the option but I am keen to keep the amount of controls on the form to a minimum.

I have a workaround (not ideal but it does the job) - Both controls .visible property is false. if I need to see the jobs grid I change that property to true.

For question 2, the .Focused property didn't work so I have put an IF statement in, saying if jobs.datagrid.visible = true then 'action the jobs code' else...

Would be a benefit if I could get it to work as originally expected but this does the trick.

Thanks a lot for your help.

John
 
I have a workaround (not ideal but it does the job) - Both controls .visible property is false.

Nothing wrong with that. I do the same thing for showing various panels, when the user select a radio button.
VB.NET:
If me.rbShowDetailsPanel.checked = True Then
   me.panelDetails.visible = True
   me.panelReport.visible = False
ElseIf me.rbShowReportPanel.checked = True Then
   me.panelDetails.visible = False
   me.panelReport.visible = True
End If



2. I need to be able to get the value of the cell in the first column of the row they are on and I have been able to get this by this code:

Code:
TBL_CustomersDataGridView.CurrentRow.Cells(0).ValueWhat I need though is instead of saying 'show me the value of the cell in the CustomersDataGridView', I would like it to say 'Show me the value of the cell in the currently displayed Datagridview. Is this possible?

Using the point above.

VB.NET:
If me.TBL_CustomersDataGridView.visible = true Then
   me.textbox1.text = TBL_CustomersDataGridView.CurrentRow.Cells(0).Value
ElseIf me.TB_JobsDataGridView.Visible = true Then
   me.textbox1.text = TBL_JobsDataGridView.CurrentRow.Cells(0).Value
End If
 
Thanks Arg, my IF statement is the same as yours and works great. Good to know the .visible route I took is a good one. Appreciate the reply.

John
 
Back
Top