Winform DataGridView
-
DataGridView's SelectionChanged Event Fire earlier than CellDoubleClick Event. But I hope SelectionChanged after CellDoubleClick. My Program require: 1> DoubleClick any part of the row, this row selected=true. read a value from this row as parameter order to open a dialog for do something. 2> When SelectionChanged, another controls's value will changed from the new selected row. But if DoubleClick fired that another controls's value need not change. How to do? Thanks.
-
DataGridView's SelectionChanged Event Fire earlier than CellDoubleClick Event. But I hope SelectionChanged after CellDoubleClick. My Program require: 1> DoubleClick any part of the row, this row selected=true. read a value from this row as parameter order to open a dialog for do something. 2> When SelectionChanged, another controls's value will changed from the new selected row. But if DoubleClick fired that another controls's value need not change. How to do? Thanks.
WinForm Controls often fire more events than you would expect. Maybe SelectionChanged fires more than once, say first to indicate a possible previous selection is no longer selected, then to tell you something new is selected. And some other events may be present in between. Suggestion: Add some logging to your event handlers to see what happens in sufficient detail. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
DataGridView's SelectionChanged Event Fire earlier than CellDoubleClick Event. But I hope SelectionChanged after CellDoubleClick. My Program require: 1> DoubleClick any part of the row, this row selected=true. read a value from this row as parameter order to open a dialog for do something. 2> When SelectionChanged, another controls's value will changed from the new selected row. But if DoubleClick fired that another controls's value need not change. How to do? Thanks.
Maybe not use DoubleClick and SelectionChanged? Use MouseDown, instead, and test for how many clicks?
if (e.Button == MouseButtons.Left) { if (e.Clicks == 1) { DoSelectionstuff(); } else if (e.Clicks == 2) { DoDoubleclickStuff(); }
Might not work... But you can set a flag in the MouseDown event indicating whether it was a 1 or a 2 click, then process your SelectionChange code appropriately.
There is water at the bottom of the ocean. My Mu[sic] My Films My Windows Programs, etc.
-
Maybe not use DoubleClick and SelectionChanged? Use MouseDown, instead, and test for how many clicks?
if (e.Button == MouseButtons.Left) { if (e.Clicks == 1) { DoSelectionstuff(); } else if (e.Clicks == 2) { DoDoubleclickStuff(); }
Might not work... But you can set a flag in the MouseDown event indicating whether it was a 1 or a 2 click, then process your SelectionChange code appropriately.
There is water at the bottom of the ocean. My Mu[sic] My Films My Windows Programs, etc.
-
Really? Not in my app. I had to use it to prevent row selection on doubleclicks. Hmm.
There is water at the bottom of the ocean. My Mu[sic] My Films My Windows Programs, etc.
-
I try to again. not always 1, but first click still call DoSelectionSuff() Then call DoDoubleClickSuff()
Ah... Try moving the code currently in the OndoubleClick into a separate function (use the Refactor tool to create the function), then "disconnect" the event from the grid. Call the separate function from the MouseDown event when 2 clicks are seen. If it doesn't work, just reconnect the DoubleClick. No harm done. :)
There is water at the bottom of the ocean. My Mu[sic] My Films My Windows Programs, etc.