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

GridControl: Changing selection in virtual tree.

Hello. I have a little problem :) I implement virtual tree grid, like in the suite samples "Virtual tree grid". But, the problem is in rows selection. When I hit collapse or expand buttons, all selected rows become unselected and selection moves to the currently expanded single row. The question is: How to avoid selection changes during expand and collapse operation. The situation could be reproduced with "Virtual tree grid" sample, you should set property ListBoxSelectionMode = One Thanks.

1 Reply

AD Administrator Syncfusion Team August 9, 2004 06:11 AM UTC

Here is code that will prevent selection changing when you click on the left side on the tree cell. But I do not know what you want dome when you close a node above the slection. This code will leave it at the row position in the grid. If you want teh same row to remain selected, then when the node is above teh selection you will have to adjust the selected row by th enumber of rows added or removed duting teh node operation.
private void gridControl1_SelectionChanging(object sender, GridSelectionChangingEventArgs e)
{
	if(e.Reason == GridSelectionReason.SetCurrentCell && Control.MouseButtons == MouseButtons.Left)
	{
		int row, col;
		Point pt = this.gridControl1.PointToClient(Control.MousePosition);
		if(this.gridControl1.PointToRowCol(pt, out row, out col, -1)
			&& col == 1)
		{
			TreeCellRenderer cr = this.gridControl1.GetCellRenderer(row, col) as TreeCellRenderer;
			Rectangle rect = cr.GetCellBoundsCore(row, col);
			int X = 20 + rect.X + cr.IndentSize * (int)this.gridControl1[row, col].Tag;
			if( pt.X < X)
				e.Cancel = true;
		}
	}
}

Loader.
Live Chat Icon For mobile
Up arrow icon