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

GridListControl - ClearSelected does not clear SelectedValue

Hi, I have a GridListControl I populate using DataBinding. When I call ClearSelected() everything seems just fine (no more selection indicator, SelectedItem is null, SelectedIndex is -1). However SelectedValue is not null. With a single entry list an can''t select that single entry anymore as SelectedValue represents that specific entry and SelectedValueChanged won''t be triggered when clicking on the (visually deselected) entry. Any help / hints would be appreciated Regards Kai Iske

9 Replies

AD Administrator Syncfusion Team June 28, 2005 03:23 PM UTC

Instead of calling ClearSelected, try setting this.gridListControl1.SelectedIndex = -1; to see if that will serve your needs.


KI Kai Iske June 29, 2005 06:11 AM UTC

Clay, same effect. The list looks like it doesn''t have any selected item. However internally there still is a SelectedValue. Thus when I click on my single entry, the SelectedValueChanged event isnt''t triggered. Looks like an issue for direct-trac? Regards Kai


AD Administrator Syncfusion Team June 29, 2005 07:39 AM UTC

I don''t see this problem in this same using 3.2.1.0. Do you? The SelecedValue changed event is raised for this single item list after setting the SelectedIndex = -1. http://www.syncfusion.com/Support/user/uploads/GDBG_GLC_da782bdd.zip Does your custom DataSource do something special with null values? If you can upload a sample here or in Direc Trac that shows the problem, we can look at it here.


KI Kai Iske July 4, 2005 07:49 AM UTC

Clay, I finally found the cause (but not the reason) for the problem. The GridListControl is hosted within a UserControl. When I move my GLC code directly to the form, it works just fine. However when being hosted within a UserControl, the first entry will alway be selected (for whatever funny reason). The attached sample will show it. When you move the UserControl OnLoad code and the GLC to the form, it works just fine. Regards Kai Test_6160.zip


AD Administrator Syncfusion Team July 4, 2005 09:39 AM UTC

I think the problem probably has to do with the order in which the calls are being made as the controls are being parented. The GridListControl is parented as the UserControl is created. At this point, the index = -1 works ok. But then the UserControl is later parentted to the form which clears the -1 settings as essentially the GriListControl is reparented at this point (as its parent is parented to the form). This worked in your sample to avoid the problem. In the UserControl.Load, subscriber to the grid''s VisibleChanged event. In the event handler, and unsubscribe and set the index. this.gridListControl1.VisibleChanged += new EventHandler(gridListControl1_VisibleChanged); private void gridListControl1_VisibleChanged(object sender, EventArgs e) { this.gridListControl1.VisibleChanged -= new EventHandler(gridListControl1_VisibleChanged); this.gridListControl1.SelectedIndex = -1; }


KI Kai Iske July 5, 2005 06:43 AM UTC

Clay, almost did it :) When the control is hosted within a Tab Control however, switching between tabs and returning to the tab hosting the user control (which in turns hosts the grid list) will activate the first row if there previously wasn''t a selection. So the VisibilityChanged approach doesn''t work here, because if there was some row selected, I would change to unselected and I simply don''t want to keep track of the currently selected row myself. Regards Kai


AD Administrator Syncfusion Team July 5, 2005 08:51 AM UTC

Another work around is the set up a Timer to fire in say 40 msecs. Enable this timer exactly where you are now trying to set the SelectedIndex = -1. Then in the Timer event, disable the timer and set SelectedIndex = -1. The idea is to let the grid get finally parented/initialized, and then set the SelectedIndex. The 40 msecs worked OK for me in the Load event to work around this problem. maybe this will work in the Tabbed case too.


KI Kai Iske July 6, 2005 08:39 AM UTC

Clay, thanks for your help, but to me it looks like if it would simply be better if the GridListControl wouldn''t select anything in the first place and only react on user interaction :) But maybe there is something I''m missing or simply don''t know about the inner workings of the GLC. Setting up a timer and resetting SelectedIndex based on some timings sounds like some heuristics rather than some deterministic behavior. I guess I stick with the solution that I simply believe that if there are items in the GLC initially the first will be selected. Regards Kai


AD Administrator Syncfusion Team July 6, 2005 09:43 AM UTC

If you add a SelectedValue changed eventhandler to your sample, and place a stop in it, you can track the selected index first being zero, then changing to -1 (as you explicitly set it), and then see it being reset to zero later. This last change that undoes the -1 setting is being triggerred by the OnBindingContextChanged event that occurs when the control is reparented. The point here is that grid is not really forcing the selection to be zero, but instead is responding to the selection being changed to zero down in the framework ListControl.OnBindingContextChanged code. I do not know that the grid can have anyway of directly determining whether it should respond to the base class changing the index or not. I think, in general, the grid has to actually set the index to what the baseclass ListControl indicates in this situation. But the GridListControl does have the option of not calling the base class in an override of this OnBindingCOntextChnaged. And this would prevent the baseclass from changing the index at this point.
public class MyGridListControl : GridListControl
{
	protected override void OnBindingContextChanged(EventArgs e)
	{
                //dont call base class
		//base.OnBindingContextChanged (e);
	}
}
The above override worked in the sample to avoid resetting the -1. Now, I did not use .NET Reflector to see what might be being missed (if anything) by not calling the baseclass. So, if you use this override, you probably should take a look to check if you need to add other code to your override.

Loader.
Live Chat Icon For mobile
Up arrow icon