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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Cancelling Row selection/SelectedIndex changes in GridListBox

Thread ID:





1453 Oct 31,2002 04:09 AM UTC Nov 1,2002 01:07 PM UTC WinForms 3
Tags: GridControl
Kai Iske
Asked On October 31, 2002 04:09 AM UTC

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

Administrator [Syncfusion]
Replied On 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)

Kai Iske
Replied On 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

Stefan Hoenig [Syncfusion]
Replied On November 1, 2002 01:07 PM UTC

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


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon