We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

can i use CellMouseDown event in virtualgrid?

I tried to use the defined CellMouseDown event, but it never raise the event. can someone give any hint? thanks in advance!

7 Replies

AD Administrator Syncfusion Team November 2, 2004 07:16 AM UTC

I could not get it to be hit either, so we will look into what is going on. Until we find out what is going on, maybe using the grid.MouseDown event will serve your purpose.
private void gridControl1_MouseDown(object sender, MouseEventArgs e)
{
	int row, col;
	Point pt = new Point(e.X, e.Y);
	if(this.gridControl1.PointToRowCol(pt, out row, out col, -1))
	{
		Console.WriteLine(string.Format("gridControl1_MouseDown {0},{1}", row, col));
	}
}


AD Administrator Syncfusion Team November 2, 2004 09:22 AM UTC

To get the CellMouseDown/CellMouseUp events to be raised, you need to handle the CellHitText event, and return a non-zero result when the mouse is over a cell where you want to get these events.
private void gridControl1_CellHitTest(object sender, GridCellHitTestEventArgs e)
{
        //get them everywhere
	e.Result = 1;
}


YA yan November 2, 2004 11:04 PM UTC

>To get the CellMouseDown/CellMouseUp events to be raised, you need to handle the CellHitText event, and return a non-zero result when the mouse is over a cell where you want to get these events. > >
>private void gridControl1_CellHitTest(object sender, GridCellHitTestEventArgs e)
>{
>        //get them everywhere
>	e.Result = 1;
>}
>
Thanks for replaying! after add CellHitTest, it did hit the CellMouseDown. however i still got some problems. My requirement is to select several cells in virtualgrid, then change the values for the selected cells. After i recorded the cell row and colum index use cellMouseDown event, move the mouse to some other cell, then tried to use CellMouseUp event to get the mouse pointed cell info.(rowIndex and colIndex), it still gave the cell info. where mouse was down. what''s the problem here? is there any other ways that i can achieve my requirement? private void gridControl1_CellMouseDown(object sender, Syncfusion.Windows.Forms.Grid.GridCellMouseEventArgs e) { this.rowSelectBegin = e.RowIndex; this.columSelectBegin = e.ColIndex; } private void gridControl1_CellMouseUp(object sender, Syncfusion.Windows.Forms.Grid.GridCellMouseEventArgs e) { this.rowSelectStop = e.RowIndex; this.columSelectStop = e.ColIndex ; }


AD Administrator Syncfusion Team November 3, 2004 04:43 AM UTC

You can use this code to get the row and col. Point pt = new Point(e.MouseEventArgs.X,e.MouseEventArgs.Y); int row, col; this.gridControl1.PointToRowCol(pt, out row, out col, -1);


AD Administrator Syncfusion Team November 4, 2004 12:24 AM UTC

>You can use this code to get the row and col. > >Point pt = new Point(e.MouseEventArgs.X,e.MouseEventArgs.Y); >int row, col; >this.gridControl1.PointToRowCol(pt, out row, out col, -1); > Thank you very much Clay, it works fine. another question, if i want to change the selected cells backcolor(some highlight effect) in virtualgrid, what am i going to do. I tried the following code, i does not change the color but the value! private int rowSelectBegin = -1, rowSelectStop = -1, columSelectBegin = -1, columSelectStop = -1; private void gridControl1_CellMouseDown(object sender, Syncfusion.Windows.Forms.Grid.GridCellMouseEventArgs e) { Point pt = new Point(e.MouseEventArgs.X,e.MouseEventArgs.Y); this.gridControl1.PointToRowCol(pt, out rowSelectBegin , out columSelectBegin, -1); } private void gridControl1_CellMouseUp(object sender, Syncfusion.Windows.Forms.Grid.GridCellMouseEventArgs e) { Point pt = new Point(e.MouseEventArgs.X,e.MouseEventArgs.Y); this.gridControl1.PointToRowCol(pt, out rowSelectStop , out columSelectStop, -1); for(int i = rowSelectBegin; i< rowSelectStop; i++) { this.gridControl1[i,columSelectBegin-1].BackColor = Color.Azure; } }


AD Administrator Syncfusion Team November 4, 2004 09:19 AM UTC

>>this.gridControl1[i,columSelectBegin-1].BackColor = Color.Azure; Code like this does not work in a virtual grid. The reason is that in a virtual grid, you are responsible for setting all cell style properties in QueryCellInfo. You cannot just set them using an indexer as there is no where for them to be stored as all the data is controlled by you. If you want to set the selection color for all selections, then you can just set grid.AlphaBlendSelectionColor (provided you have set the GridSelectionsFlags.AlphaBlend in the AllowSelections property). If you only want to change the some selections, then you could use your code above to save the range to want to color. Then in QueryCellInfo, you could check to see if teh e.RowIndex and e.ColIndex are in this saved range. If so, set e.Style.BackCOlor.


YA yan November 8, 2004 03:33 AM UTC

Thank you very much for the great help! >>>this.gridControl1[i,columSelectBegin-1].BackColor = Color.Azure; > >Code like this does not work in a virtual grid. The reason is that in a virtual grid, you are responsible for setting all cell style properties in QueryCellInfo. You cannot just set them using an indexer as there is no where for them to be stored as all the data is controlled by you. > >If you want to set the selection color for all selections, then you can just set grid.AlphaBlendSelectionColor (provided you have set the GridSelectionsFlags.AlphaBlend in the AllowSelections property). > >If you only want to change the some selections, then you could use your code above to save the range to want to color. Then in QueryCellInfo, you could check to see if teh e.RowIndex and e.ColIndex are in this saved range. If so, set e.Style.BackCOlor.

Loader.
Up arrow icon