Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid selected

Status
Not open for further replies.

qazz

Programmer
Oct 6, 2002
13
PH
I have 2 datagrid in a form and i want to know which datagrid is selected when i click a command button it will identify which datagrid is selected.

Thanks.
 
Can you clarify your question? When the command button is clicked neither of the datagrids will be selected.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
johnwm,

I have 2 datagrid in a form namely Datagrid1 & Datagrid2 and it connected with a table ItemMasterlist and ItemDetails respectively and command button Edit. If the user click Edit Button, they must check which table is to be edit. For example, if the datagrid1 is click before the edit button was click then the ItemMasterlist should be edit. It is possible?

Thanks.
 
You could set up a public variable at the form level and set it to some value in the GotFocus event for each grid. That would work as long as you could guarantee that at least one of the grids had received the focus.

Another possibility is two edit buttons ... one for each grid so there's no need to try to figure out which one to edit.

As johnwm says, when you click the button then it has the focus, not one of the datagrids.
 
Golom,

Thanks for your advice. I will try.

Arnold
 
A small point: it doesn't need to be a public variable, it needs to be at least a module level variable. I think that's what Golom means. But to clarify, qazz, you have to put the variable in the General Declarations area of the form, but it can be declared as Private.

Also, you can guarantee that at least one of the grids has received focus by setting its tabindex property to 0.

So:
Code:
'General Declarations section of the form
Private ActiveGrid as DataGrid

Private Sub Form_Load()
Set ActiveGrid = DataGrid1 'Where DataGrid1 has a TabIndex of 0
End Sub

Private Sub DataGrid1_GotFocus()
Set ActiveGrid = DataGrid1
End Sub

Private Sub DataGrid2_GotFocus()
Set ActiveGrid = DataGrid2
End Sub

Private Sub cmdEdit_Click()
With ActiveGrid
   .SetFocus
   .EditActive = True
End With
End Sub
Now, this is fine if you have no other controls on your form but the DataGrids and your command button. If you have other controls, and you want to disable the command button when the focus isn't on one of the Datagrids, things get a bit messy. Furthermore, I'm not sure what you have planned to get OUT of edit mode. But hopefully, this will give you a bit of a start.

HTH

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top