Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Developer,

I am working with WPF application where I have a Listbox with following syntax.

XML
<Window.Resources>
        <DataTemplate x:Key="ListBoxItemTemplate" >
            <!--<WrapPanel>-->
                <CheckBox Name="CheckBoxZone" Content="{Binding SoilStatus}" Margin="3, 10" Tag="{Binding ID}" />
            <!--</WrapPanel>-->
        </DataTemplate>
    </Window.Resources>


XML
<ListBox Grid.Row="0" Grid.Column="1" Margin="3 10" Name="lstSoilStatus"  ItemTemplate="{DynamicResource ListBoxItemTemplate}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                            <ListBox.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <WrapPanel Orientation="Horizontal"></WrapPanel>
                                </ItemsPanelTemplate>
                            </ListBox.ItemsPanel>
                        </ListBox>


I am binding this value from code, following is the code to bind:

string query = "SELECT ID, SoilStatus FROM SoilStatus ORDER BY SoilStatus";
                DBOperation obj = new DBOperation();
                DataTable dt = obj.GetData(query);
                lstSoilStatus.ItemsSource = dt.AsDataView();


My code is working as expected.
Now I am selecting multiple checkbox as my requirement.
And I want to get the tag value of that selected checkbox in c# code.
How can I achieve this?
Any idea?
Posted
Comments
LLLLGGGG 20-Oct-15 16:16pm    
You may try to use a class that contains your object (the one you bind the list from) and a boolean value which is checked/unchecked. Then you can iterate through that collection and find the checked entries. Oh, remember to bind the IsChecked property of the CheckBox to your value.

Hope this helps.

PS: you may try this: http://merill.net/2009/10/wpf-checked-listbox/
kailash_tandel87 22-Oct-15 4:38am    
Thanks buddy! It works...
LLLLGGGG 22-Oct-15 15:18pm    
You're welcome anytime!

1 solution

Hi,

You may try to use a class that contains your object (the one you bind the list from) and a boolean value which is checked/unchecked. Then you can iterate through that collection and find the checked entries. Oh, remember to bind the IsChecked property of the CheckBox to your value.

Hope this helps.

PS: you may try this: http://merill.net/2009/10/wpf-checked-listbox/

I put the answer here in order to tell other that it has a solution. :-)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900