Sanmarie
asked on
How to simulate click event on datagrid
using .NEt 1.1, Windows forms, VB.NET
I have a datagrid where I color certain rows red. I had to override the DatagridTextBoxColumn class to get this to work. The user can filter the data on the datagrid. The problem is when the data is filtered, unless the grid is clicked, the paint event (that colors the rows red) does not get fired.
I have tried dataGrid.Focus and dataGrid.Refresh and it still doesn't work. I have to click on the grid for the coloring to take place. Is there a way to simulate the click event on the grid?
Thanks
San
I have a datagrid where I color certain rows red. I had to override the DatagridTextBoxColumn class to get this to work. The user can filter the data on the datagrid. The problem is when the data is filtered, unless the grid is clicked, the paint event (that colors the rows red) does not get fired.
I have tried dataGrid.Focus and dataGrid.Refresh and it still doesn't work. I have to click on the grid for the coloring to take place. Is there a way to simulate the click event on the grid?
Thanks
San
You may only have to invalidate the regions being colored, in your case the DataGridTextBoxColumn.
ASKER
Sorry for the delay in responding to you.
But your suggestions don't work. I still have to click the grid to see the colored regions. So is there a way to simulate a click event on a grid?
Thanks
San
But your suggestions don't work. I still have to click the grid to see the colored regions. So is there a way to simulate a click event on a grid?
Thanks
San
Yes. Create an event OnClick fro the dataklick, and call it from wherever you want to. This will simulate a click
ASKER
Any code links on how to code this OnClick event
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok. I will look at this code and get back to you.
Thanks
San
Thanks
San
ASKER
Let me ask the question in a different way.
Is there a way to programmatically click the grid without physically using the mouse to do it. That is, I want the click event to occur from my program.
Help as I don't understand your solutions
San
Is there a way to programmatically click the grid without physically using the mouse to do it. That is, I want the click event to occur from my program.
Help as I don't understand your solutions
San
The following code emulates a left mouse click at a specific point on a specific window.To use the code add the following line to the file's using block:
using System.Runtime.InteropServ ices;
Then you can use the following code:
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);
public const int WM_LBUTTONDOWN = 513;
public const int WM_LBUTTONUP = 514;
public void EmulateLMClick(int x, int y)
{
SendMessage(this.Handle, WM_LBUTTONDOWN, 1, ((y << 16) | x));
SendMessage(this.Handle, WM_LBUTTONUP, 0, ((y << 16) | x));
}
using System.Runtime.InteropServ
Then you can use the following code:
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);
public const int WM_LBUTTONDOWN = 513;
public const int WM_LBUTTONUP = 514;
public void EmulateLMClick(int x, int y)
{
SendMessage(this.Handle, WM_LBUTTONDOWN, 1, ((y << 16) | x));
SendMessage(this.Handle, WM_LBUTTONUP, 0, ((y << 16) | x));
}
ASKER
Thanks iHadi,
Do you have the same code in VB.NET?
I will try it and get back to you
Do you have the same code in VB.NET?
I will try it and get back to you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks I added your code and it compiled fine but it doesn't solve my problem.
I still have to physically click on the grid for the row to be painted in red color. I debugged using the same x and y co-ordinates that I would click using the mouse and it doesn't work. Somehow the paint event of the DataGridTextBoxColumn only gets fired when I physically click on the grid or tab into it. Otherwise, it doesn't work.
Thanks
San
I still have to physically click on the grid for the row to be painted in red color. I debugged using the same x and y co-ordinates that I would click using the mouse and it doesn't work. Somehow the paint event of the DataGridTextBoxColumn only gets fired when I physically click on the grid or tab into it. Otherwise, it doesn't work.
Thanks
San
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
No, it still doesn't work. Even when I use the mouse to resize, the paint method doesn't get fired. Now, when I click, it works.
San
No, it still doesn't work. Even when I use the mouse to resize, the paint method doesn't get fired. Now, when I click, it works.
San
ASKER
I just noticed something.
The rows do get painted red, just not the first one. I have to click into the grid for the first row to get painted. Strange, really strange.
The rows do get painted red, just not the first one. I have to click into the grid for the first row to get painted. Strange, really strange.
ASKER
I guess there is no solution. I will just keep tryhing alternatives. Thanks for your inputs though. If it's still a problem, I will pose a new question.
Thanks
San
Thanks
San
I'm using VS 2005 and I don't know if the following method is valid for VS 2003.
Try calling the Invalidate method of the control:
dataGrid.Invalidate();
This method forces the control to redraw itself;