SelectAll Checkbox option inside combobox

6 posts, 0 answers
  1. VS
    VS avatar
    101 posts
    Member since:
    Jul 2008

    Posted 11 Jul 2010 Link to this post

    Hi All,

    I was able to put checkbox for all combobox items. Now I need to have a SelectAll checkbox as the first option inside the combobox. I was successful in that as well. But I would like to know the currently selected checkbox item from the Method bounded to the Command of the checkbox otherwise the SelectAll option will not work as expected.

    <

     

    DataTemplate x:Key="RowItemDataTemplate">

     

     

     

    <CheckBox x:Name="rowCheckbox" Margin="2,2"

     

     

    Command="{Binding Path=DataContext.RowCheckCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}"

     

     

    Content="{Binding Path=RowName}"

     

     

    IsChecked="{Binding Path=IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

     

     

     

    </DataTemplate>

     


    <

     

    ComboBox Grid.Row="0" Grid.Column="2" x:Name="cboRows" Style="{DynamicResource ValidatingComboBox}"

     

     

    ItemsSource="{Binding RowItems}"

     

     

    ItemTemplate="{StaticResource RowItemDataTemplate}"

     

     

    Text="{Binding SelectedRowsText}"

     

     

    IsEditable="True" Margin="5,0,0,0"

     

     

    IsReadOnly="True"

     

     

    MaxDropDownHeight="140"/>

     


    public

     

    ICommand RowCheckCommand

     

    {

     

    get

     

    {

     

    if (_rowCheckCommand == null)

     

    {

    _rowCheckCommand =

    new RelayCommand(

     

    param => RowCheckBoxChanged(),

    param =>

    true

     

    );

    }

     

    return _rowCheckCommand;

     

    }

    }


    public

     

    void RowCheckBoxChanged()

     

    {

    NotifySelectedRowsText();

    }


    Is there a way, that i can pass the currently selected checkbox item to RowCheckBoxChanged() method?
    I had been doing this in wpf combobox. Since i can't find any solution to my problem, i was thinking to shift to Telerik combobox, if it can solve my problem.

    Any idea/suggestion will be greatly appreciated.

    Regards

    SVP
  2. VS
    VS avatar
    101 posts
    Member since:
    Jul 2008

    Posted 11 Jul 2010 Link to this post

    I found out thanks.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Keneo
    Keneo avatar
    5 posts
    Member since:
    Jul 2010

    Posted 27 Jul 2010 Link to this post

    Hi can you send the code for the checkboxcombo you have implemented.
  5. VS
    VS avatar
    101 posts
    Member since:
    Jul 2008

    Posted 28 Jul 2010 Link to this post

    <

     

    DataTemplate x:Key="RowItemDataTemplate">

     

     

     

    <StackPanel>

     

     

     

    <CheckBox x:Name="rowSelectAllCheckbox" Margin="2,2"

     

     

    Command="{Binding Path=DataContext.RowSelectAllCheckCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}"

     

     

    Content="{Binding Path=RowName}" Width="150"

     

     

    IsChecked="{Binding Path=IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"

     

     

    Visibility="{Binding Path=IsSelectAllVisible, Converter={StaticResource BooleanToVisibility}}" />

     

     

     

    <CheckBox x:Name="rowCheckbox" Margin="2,2"

     

     

    Command="{Binding Path=DataContext.RowCheckCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}"

     

     

    Content="{Binding Path=RowName}" Width="150"

     

     

    IsChecked="{Binding Path=IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"

     

     

    Visibility="{Binding Path=IsVisible, Converter={StaticResource BooleanToVisibility}}" />

     

     

     

    </StackPanel>

     

     

     

    </DataTemplate>

     

    public

     

    class RowItem

     

     

     

     

    {

     

    public Row Row { get; set; }

     

     

    public string RowName { get; set; }

     

     

    public bool IsSelected { get; set; }

     

     

    public bool IsSelectAllVisible { get; set; }

     

     

    public bool IsVisible { get; set; }

     

     

    public RowItem(Row row, bool isSelected)

     

    {

    Row = row;

    RowName =

    "Row " + GridRow + " - " + Row.RowName;

     

    IsSelected = isSelected;

    IsSelectAllVisible =

    false;

     

    IsVisible =

    true;

     

    }

     

    public RowItem(string name)

     

    {

     

    var row = new Row(name, name);

     

    Row = row;

    RowName = name;

    IsSelectAllVisible =

    true;

     

    IsVisible =

    false;

     

    }

    }

     


     

    private

     

    void LoadSectionRowsDropDown(TestObj test)

     

    {

    RowItems =

    new ObservableCollection<RowItem>();

     

     

    foreach (var row in test.Rows)

     

    {

     

    var rowItem = new RowItem(row, false);

     

    RowItems.Add(rowItem);

    }

     

    var selectAllRowItem = new RowItem("Select All");

     

    RowItems.Insert(0, selectAllRowItem);

    }

     

     

    <

     

    ComboBox Grid.Row="0" Grid.Column="1" x:Name="cboRows" Style="{DynamicResource ValidatingComboBox}"

     

     

     

     

     

    ItemsSource="{Binding RowItems}"

     

     

     

     

     

    ItemTemplate="{StaticResource RowItemDataTemplate}"

     

     

     

     

     

    Text="{Binding SelectedRowsText}"

     

     

     

     

     

    IsEditable="True" Margin="5,0,0,0"

     

     

    IsReadOnly="True"

     

     

     

     

     

    MaxDropDownHeight="140"/>

     



  6. Keneo
    Keneo avatar
    5 posts
    Member since:
    Jul 2010

    Posted 30 Jul 2010 Link to this post

    Thank you.
  7. gans
    gans avatar
    48 posts
    Member since:
    Jan 2012

    Posted 29 Mar 2012 Link to this post

    Hi VS, 

    Do you have a working example that you can post please? In the code posted what is "Row" class supposed to have?
Back to Top
UI for WPF is Visual Studio 2017 Ready