Ctrl + MouseClick using PostMessage is not working for DataGridview.
-
I have a C# application with a ListView and GridView control.
I would like to simulate the mouse click in both control simultaneously.
I would like to work this functionality even if the wind is not foreground.
So I used PostMessage to do the selection./// /// Select rows. /// /// List of rows to be selected. /// SelectionType. private void PerformSelection( List rows, SelectionType selctionType ) { // timer1.Start(); IntPtr wParam = MK\_CONTROL; switch ( selctionType ) { case SelectionType.Ctrl: wParam = MK\_CONTROL; dataGridView1.VirtualKey = Keys.Control; break; case SelectionType.Shift: wParam = MK\_SHIFT; dataGridView1.VirtualKey = Keys.Shift; break; case SelectionType.CtrlShift: wParam = MK\_CONTROLSHIFT; break; } dataGridView1.Focus(); foreach (int rowIndex in rows) { SetScrollPositionListView( rowIndex ); NativeMethods.PostMessage( listView1.Handle, WM\_LBUTTONDOWN, wParam, (IntPtr) ( ( listView1.Items\[rowIndex\].Position.Y << 16 ) | listView1.Items\[rowIndex\].Position.X ) ); NativeMethods.PostMessage( listView1.Handle, WM\_LBUTTONUP, wParam, (IntPtr) ( ( listView1.Items\[rowIndex\].Position.Y << 16 ) | listView1.Items\[rowIndex\].Position.X ) ); SetScrollPosition(rowIndex); dataGridView1.Focus(); // Get position of dgv row in dgv. Rectangle dgvRect = dataGridView1.GetRowDisplayRectangle(rowIndex, true); NativeMethods.PostMessage(dataGridView1.Handle, WM\_LBUTTONDOWN, wParam, (IntPtr)((dgvRect.Top + 1 << 16) | dgvRect.Left + 1)); NativeMethods.PostMessage(dataGridView1.Handle, WM\_LBUTTONUP, wParam, (IntPtr)((dgvRect.Top + 1 << 16) | dgvRect.Left + 1)); } } /// /// Scroll to invisible rows. /// /// Index of row to be selected.
-
I have a C# application with a ListView and GridView control.
I would like to simulate the mouse click in both control simultaneously.
I would like to work this functionality even if the wind is not foreground.
So I used PostMessage to do the selection./// /// Select rows. /// /// List of rows to be selected. /// SelectionType. private void PerformSelection( List rows, SelectionType selctionType ) { // timer1.Start(); IntPtr wParam = MK\_CONTROL; switch ( selctionType ) { case SelectionType.Ctrl: wParam = MK\_CONTROL; dataGridView1.VirtualKey = Keys.Control; break; case SelectionType.Shift: wParam = MK\_SHIFT; dataGridView1.VirtualKey = Keys.Shift; break; case SelectionType.CtrlShift: wParam = MK\_CONTROLSHIFT; break; } dataGridView1.Focus(); foreach (int rowIndex in rows) { SetScrollPositionListView( rowIndex ); NativeMethods.PostMessage( listView1.Handle, WM\_LBUTTONDOWN, wParam, (IntPtr) ( ( listView1.Items\[rowIndex\].Position.Y << 16 ) | listView1.Items\[rowIndex\].Position.X ) ); NativeMethods.PostMessage( listView1.Handle, WM\_LBUTTONUP, wParam, (IntPtr) ( ( listView1.Items\[rowIndex\].Position.Y << 16 ) | listView1.Items\[rowIndex\].Position.X ) ); SetScrollPosition(rowIndex); dataGridView1.Focus(); // Get position of dgv row in dgv. Rectangle dgvRect = dataGridView1.GetRowDisplayRectangle(rowIndex, true); NativeMethods.PostMessage(dataGridView1.Handle, WM\_LBUTTONDOWN, wParam, (IntPtr)((dgvRect.Top + 1 << 16) | dgvRect.Left + 1)); NativeMethods.PostMessage(dataGridView1.Handle, WM\_LBUTTONUP, wParam, (IntPtr)((dgvRect.Top + 1 << 16) | dgvRect.Left + 1)); } } /// /// Scroll to invisible rows. /// /// Index of row to be selected.
-
-
Yes, the PostMessage is returning true as always. The focus is in datagidview. I have updated my query with an explanatory code snippet. Could you please have a look at that also.
aks
Don't take it the wrong way, but can you verify the setting of the DataGridViews MultiSelect[^] property? Verify that it's set to true? Also, if you have a pointer to the datagridview-object, then why not simply set the collected items using code?
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
Don't take it the wrong way, but can you verify the setting of the DataGridViews MultiSelect[^] property? Verify that it's set to true? Also, if you have a pointer to the datagridview-object, then why not simply set the collected items using code?
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
Yes, I reassured the DataGridView's MultiSelect property is true. From GIO i am able to multi select the rows by using Ctrl and Shift. Thank you Eddy for the suggestion But my intention id an automation interface which works for both ListView and DataGridView. I surely need to simulate the actual user selection by PostMessage.
aks
-
Yes, I reassured the DataGridView's MultiSelect property is true. From GIO i am able to multi select the rows by using Ctrl and Shift. Thank you Eddy for the suggestion But my intention id an automation interface which works for both ListView and DataGridView. I surely need to simulate the actual user selection by PostMessage.
aks
aks. wrote:
I reassured the DataGridView's MultiSelect property is true.
Can you (debug).print the amount of rows selected? Kinda hoping that the selection is there, but not correctly shown (think "HideSelection" properties and the likes).
aks. wrote:
I surely need to simulate the actual user selection by PostMessage.
Not really; one does not need to test whether the DataGridView still handles mouse-messages correctly - that part of the code did not change. And it does not "have" to be using windows-messages, you could use the PerformClick method from a button to simulate a mouseclick. Is there anyone looking at the grid and view when the test-suite makes it selection? Or does the test run without supervision?
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]