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
close icon

Cancelling Row selection/SelectedIndex changes in GridListBox

Hi, again, it's me. I've been playing around with a GridListBox as the ListBox for a ComboBoxExt. What I want to do is display a two level hierarchy in my GridListBox where only level 1 (leaf nodes) entries of my hierarchy are to be selectable. Now, what I wanted to do is catch and cancel row selections/selectedindex change events, when the user tries to select a root level item, thus preventing the ComboBox from hiding/selecting that item. Basically, I want to restrict selecting items within the displayed list to those items I control, i.e. the first level down the hierarchy. I have tried to do so using overrides of: GridSelectionChanged GridCurrentCellActivated OnSelectedIndexChanged However, somewhere down the track the selectedindex still seems to be changed thus resulting in the ComboBox closing the dropdown. Any help would be, again, highly appreciated. Regards Kai Iske DWS Investments

3 Replies

AD Administrator Syncfusion Team October 31, 2002 06:02 AM UTC

One way I think you can do this is to set the GridStyleInfo.Enabled = false for the rows in the embedded GridControl (of the GridListControl) that you want to ignore. Then override the OnMouseUp method of the GridListControl to ignore the mouseup for the disabled rows (this will prevent the dropdown from closing). So, in your formload, hook the QueryCellInfo event for the embedded grid, and use that event to mark the rows you want to be disabled.
//in form load
this.gridListControl1.Grid.QueryCellInfo += new Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventHandler(grid_QueryCellInfo);

//the handler
private void grid_QueryCellInfo(object sender, Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventArgs e)
{  //ID the rows to be disabled somehow...
	if(e.RowIndex > 0 && e.RowIndex % 3 == 0)
	{
		e.Style.BackColor = Color.Gray;
		e.Style.Enabled = false;
		e.Handled = true;
	}
}

//derived class with override
public class MyGridListControl : GridListControl
{
	protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
	{
		if(e.Button == MouseButtons.Left) 
		{
			int row = this.Grid.TopRowIndex + this.Grid.ViewLayout.PointToClientRow(new Point(e.X, e.Y)) - 1;
			if( this.Grid[row, 1].Enabled == false)
					return;
		}
		base.OnMouseUp(e);
	}
}


KI Kai Iske November 1, 2002 11:23 AM UTC

Clay, thank you very much. Works like a charm. Another thing I have noticed though: When I set FillLastColumn = tue, it does not work when the GridListControl is popped up the first time as part of a ComboBoxExt. Columns seem to have standard sizes with grey (KnownColor.Control) background to the right of the right-most column. When I move the mouse over items they get highlighted over the full width of the control and when they get deselected, the row will have a white background all the way. It seems like the initial setup of the GridListControl is missing something here. Thanks Kai Iske DWS Investments


SH Stefan Hoenig Syncfusion Team November 1, 2002 01:07 PM UTC

We know about that problem and the fix will be availabe with our upcoming release. Thanks. Stefan

Loader.
Live Chat Icon For mobile
Up arrow icon