This is a migrated thread and some comments may be shown as answers.

Disabling some checkboxes

3 Answers 73 Views
DataBoundListBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
eBuddy
Top achievements
Rank 1
eBuddy asked on 20 Mar 2012, 11:18 AM
Hi,
I need to prevent some checkboxes from being unchecked in list.
I find those checkboxes by traversing visual tree, set IsEnabled=false. Their visual state changes to gray.
But if i click checkbox - it becomes unchecked and visual state is like for normal state.

This is a really strange bug. To my mind controls have to ignore interactions if they are disabled.
Could you please have a look at that ?

Thanks

3 Answers, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 21 Mar 2012, 10:06 AM
Hi,

The checkbox behavior withing the visual containers of RadDataBoundListBox is slightly different. Since visual containers are data bound and reused by the UI virtualization mechanism, directly setting properties of the visual elements inside the element tree of a container is not correct.

If you wish to prevent an item from being checked/unchecked, you can use the ItemCheckedStateChanging event exposed by RadDataBoundListBox and cancel it in case you do not want the state of the item to change.

If you also wish to make the checkbox within the container appear disabled, you can use the ItemStateChanged event and listen for the Realized and Recycled states in order to set the IsEnabled property of the checkbox and clear it to allow the container to be correctly reused for other items. The code could look like the following:

void radDataBoundListBox_ItemStateChanged(object sender, Telerik.Windows.Controls.ItemStateChangedEventArgs e)
{
    if (e.State == Telerik.Windows.Controls.ItemState.Realized)
    {
        RadDataBoundListBoxItem container = this.radDataBoundListBox.GetContainerForItem(e.DataItem) as RadDataBoundListBoxItem;
        ItemCheckBox checkBox = ElementTreeHelper.FindVisualDescendant<ItemCheckBox>(container);
        if (shouldDisable)
        {
            checkBox.IsEnabled = false;
        }
        else
        {
            checkBox.ClearValue(ItemCheckBox.IsEnabledProperty);
        }
    }
}

I hope this helps.

Greetings,
Deyan
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
eBuddy
Top achievements
Rank 1
answered on 21 Mar 2012, 01:08 PM
Thanks for the tip with cancelling checking on ItemCheckedStateChanging event. It worked great.

But using radDataBoundListBox_ItemStateChanged event handler you provided items looks disabled only first time. If the user try to check them, their visual state changes to "Pressed" and "Checked" regardless of IsEnabled property (with false value).
0
Deyan
Telerik team
answered on 21 Mar 2012, 03:42 PM
Hi,

Thanks for writing back.

I was able to reproduce this and can confirm that this is an issue which we are going to address. Since we release Internal Builds on weekly basis we will be able to include the fix for this case in our forthcoming IB and you will be able to download and use it from your account.

Let me know in case you have further questions or need assistance.

Kind regards,
Deyan
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
DataBoundListBox
Asked by
eBuddy
Top achievements
Rank 1
Answers by
Deyan
Telerik team
eBuddy
Top achievements
Rank 1
Share this question
or