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

SelectAll Checkbox option inside combobox

5 Answers 145 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
VS
Top achievements
Rank 1
VS asked on 12 Jul 2010, 12:42 AM
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

5 Answers, 1 is accepted

Sort by
0
VS
Top achievements
Rank 1
answered on 12 Jul 2010, 02:42 AM
I found out thanks.
0
Keneo
Top achievements
Rank 1
answered on 27 Jul 2010, 11:47 AM
Hi can you send the code for the checkboxcombo you have implemented.
0
VS
Top achievements
Rank 1
answered on 28 Jul 2010, 05:28 AM

<

 

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"/>

 



0
Keneo
Top achievements
Rank 1
answered on 30 Jul 2010, 06:41 AM
Thank you.
0
gans
Top achievements
Rank 1
answered on 29 Mar 2012, 08:08 PM
Hi VS, 

Do you have a working example that you can post please? In the code posted what is "Row" class supposed to have?
Tags
ComboBox
Asked by
VS
Top achievements
Rank 1
Answers by
VS
Top achievements
Rank 1
Keneo
Top achievements
Rank 1
gans
Top achievements
Rank 1
Share this question
or