Hi All,
I have a vb net program that shows a datagridview which pulls data from a mySQL database. When the user clicks on a row (I am checking for a 'cellclick' event), a text box is filled with data from a hidden column in the datagridview. This works fine and runs without error, BUT...
When I use the cursor keys to move the selection up or down, the row highlight changes, but doesn't update the text box. I realise that this is because I am looking for a 'cellclick' event, but I don't know how to look for cursor keys as well.

Please could someone tell me what event I should be looking for to capture input via both mouse click and cursor. I have changed the program so it updates the second dgv on 'selectionchanged' but this crashes at run time with an InvalidCastException.
Alternatively, is it possible to stop the user using the cursor keys?

Many thanks,
Toomutch

Recommended Answers

All 5 Replies

you could try the cursorChanged event

you could try the cursorChanged event

the cursorchanged event does not activate when using either mouse or cursor keys to change the selection in the dgv.

I have tried selectionchanged event, but this crashes on form load (presumably loading the datagrid on formload is classed as a selctionchange and triggers the event too early?)

try to use mouse hover event of the grid and place your binding code in it ,

Regards

finally got it sorted. I was showing data in a datagridview, and when the user clicked a row, text was sent to a textbox. However, once a row had been selected it was possible for the user to change the row by using the up and down cursor keys. This wasn't picked up by the 'cellclick' event.

I moved all of the code from within the cellclick event into a new sub "updateTextBox" and called this sub from the cellclick event. I then added new events "keyup" and "keydown" and called the "updateTextBox" sub from each.

Thanks for all the input folks.

Toomutch

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.