Jump to content
Xtreme .Net Talk

How does one trap 'click' or 'double click' events in a datagrid cell?


Recommended Posts

Posted

Hello,

 

I am using a datagrid on a database form in VB from which I would like to be able to establish and perform a piece of code upon a double click within the cell.

 

My dilema is that while in the 'edit' mode of the form, when I double click on a any cell in the datagrid, the entire datagrid is selected and takes me to the following:

 

Private Sub grdButton_Assignment_Table_Navigate(ByVal sender As System.Object, ByVal ne As System.Windows.Forms.NavigateEventArgs) Handles grdButton_Assignment_Table.Navigate

 

End Sub

 

I can find no reference in the MSDN libraries that would show how one could 'trap' on a 'double click' within a cell and add code to that 'trap'.

 

If I can not 'trap' on a 'double click' then I could otherwise allow the user to 'select' a file through a button trap (which I have tried) however I can find no method for pushing the subsequent string of data into the last selected cell in the datagrid.

 

Any ideas?

Thanks for any assistance provided and take care,

 

Hdokes

  • Moderators
Posted

The thing about Click and DoubleClick events is that they are at the Datagrid level and not the Cell level.

You can use the CurrentCellChanged event to pinpoint which Cell the user clicks on.

Visit...Bassic Software
Posted

Or, with a lot of hassle, you could use the MouseDown event of the DataGrid, because the mousedown eventargs contain the X,Y coordinates.

 

This would make it possible for you to compute, which cell the cursor is actually over right now.

.nerd
  • Moderators
Posted

Heiko, why go to all that hassle when you can simply get the exact cell clicked using CurrentCellChanged. Either way we're not getting the Double-click.

 

'This gets the column and row...

Datagrid1.CurrentCell.ColumnNumber
Datagrid1.CurrentCell.RowNumber

'or if you wanted to know the column name so as to perform a query based on the Dataset...

Dataset1.Tables(0).Columns(Datagrid1.CurrentCell.ColumnNumber).ColumnName.ToString

Visit...Bassic Software
Posted

Greetings again,

 

Thanks Robby for the info. This at least allows me to 'push' a text string into the last cell selected which in the end is what I wanted to achieve. Seems a bit odd however that there are no immediate mouse events that can be captured when clicking inside the datagrid. This would have made the process I am working on more seemless and would have eliminated a couple a step that the user is forced to initiate... i.e.... click on a button after selecting the cell.

 

I used the following line to 'fill' the cell....

 

grdButton_Assignment_Table.Item(grdButton_Assignment_Table.CurrentCell.ColumnNumber, grdButton_Assignment_Table.CurrentCell.RowNumber) = openFileDialog1.FileName

Thanks for any assistance provided and take care,

 

Hdokes

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...