none
how to re-strict only one check box checked by using toolkit:ListBoxDragDropTarget

    Question

  • i am using listDragDropListBox and trying to re-strict user one checked checkbox and if user checked other check box 1st one auto uncheck , i tried but did not get correct combination any one can help,

    this work if single list box but if you drag any other Listbox then try to select one check box wont allow.

    below all code what i am doing

      <DataTemplate x:Key="ItemTemplate">
                <StackPanel Orientation="Horizontal">
                    <CheckBox HorizontalAlignment="Left" Content="{Binding Desc}" Width="20"  Checked="CheckBoxChecked" Unchecked="CheckBoxUnchecked"  IsChecked="{Binding UnChecked}"   IsThreeState="True"  Loaded="CheckBoxLoaded" Click="CheckBox_Click"/>
                    <TextBlock Text="{Binding Desc}"/>
    
                </StackPanel>
            </DataTemplate>
    
    
     <toolkit:ListBoxDragDropTarget AllowDrop="True"  x:Name="ListOptionTarget2" Height="121" VerticalAlignment="Top" Margin="4,199,0,0" d:LayoutOverrides="GridBox" Width="237" HorizontalAlignment="Left" Grid.RowSpan="2">
                <ListBox Height="113" Width="237" x:Name="cboOptiontarget2" ItemTemplate="{StaticResource ItemTemplate}" ItemsSource="{Binding Collection}" SelectionMode="Extended"  BorderThickness="1" Margin="0" >
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Vertical"/>
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                </ListBox>
            </toolkit:ListBoxDragDropTarget>
    
    Main()
    {
     _optiondata.Add(new OptionData(){Desc="ELA", UnChecked=false});
                _optiondata.Add(new OptionData(){Desc="ELB", UnChecked=false});
                _optiondata.Add(new OptionData(){Desc="ELC", UnChecked=true});
                _optiondata.Add(new OptionData(){Desc="ELD", UnChecked=false});
                _optiondata.Add(new OptionData(){Desc="ELE", UnChecked=false});
                _optiondata.Add(new OptionData(){Desc="ELF", UnChecked=false});
                _optiondata.Add(new OptionData(){Desc="ELG", UnChecked=true});
                _optiondata.Add(new OptionData(){Desc="ELH", UnChecked=false});
                _optiondata.Add(new OptionData(){Desc="ELI", UnChecked=false});
                _optiondata.Add(new OptionData(){Desc="ELJ", UnChecked=false});
    
                cboOptiontarget2.ItemsSource =_optiondata;
    
    }
    
      private void CheckBoxChecked(object sender, RoutedEventArgs e)
            {
                if (cboOptiontarget2.Items.Count > 0)
                {
                    _optiondata = new ObservableCollection<OptionData>();
                    cboOptiontarget2.Items.Clear();
                    _optiondata.Add(new OptionData() { Desc = "ELA", UnChecked = false });
                    _optiondata.Add(new OptionData() { Desc = "ELB", UnChecked = false });
                    _optiondata.Add(new OptionData() { Desc = "ELC", UnChecked = false });
                    _optiondata.Add(new OptionData() { Desc = "ELD", UnChecked = false });
                    _optiondata.Add(new OptionData() { Desc = "ELE", UnChecked = false });
                    _optiondata.Add(new OptionData() { Desc = "ELF", UnChecked = false });
                    _optiondata.Add(new OptionData() { Desc = "ELG", UnChecked = false });
                    _optiondata.Add(new OptionData() { Desc = "ELH", UnChecked = false });
                    _optiondata.Add(new OptionData() { Desc = "ELI", UnChecked = false });
                    _optiondata.Add(new OptionData() { Desc = "ELJ", UnChecked = false });
    
                    cboOptiontarget2.ItemsSource = _optiondata;
                }
            }
    
    
    
     public class OptionData : INotifyPropertyChanged
        {
          
    
            public string _desc;
    
            public bool? _unChecked = false;
    
           
    
            public string Desc
            {
                get { return _desc; }
                set
                {
                    if (value != _desc)
                    {
                        _desc = value;
                        onPropertyChanged(this, "Desc");
                    }
                }
            }
    
            public bool? UnChecked
            {
                get { return _unChecked; }
                set
                {
                    if (value != _unChecked)
                    {
                        _unChecked = value;
                        //onPropertyChanged(this, "UnChecked");
                    }
                }
            }
    
            public event PropertyChangedEventHandler PropertyChanged;
            private void onPropertyChanged(object sender, string propertyName)
            {
    
                if (this.PropertyChanged != null)
                {
                    PropertyChanged(sender, new PropertyChangedEventArgs(propertyName));
                }
            }
    
        }
    
    
    
    
    
    
    
    
    
    


     

    Thursday, June 23, 2011 3:09 PM

Answers

  •   private void CheckBoxChecked(object sender, RoutedEventArgs e)
            {
                CheckBox chkbx=sender as CheckBox;
    			OptionData context=chkbx.DataContext;
                context.UnChecked=true;
                    foreach(OptionData data in _optiondata)
    				{
    					if(context != data)
    						data.UnChecked=false;
    				}               
    
                    cboOptiontarget2.ItemsSource = _optiondata;
                }
            }

    Change your CheckBoxChecked event as given above.

    Friday, June 24, 2011 2:05 AM