none
DataGridCheckBoxColumn selection

    Question

  • Hello sir,

                Sir i have problem on datagrid, in my data grid one column is DataGridCheckBoxColumn i shown this below
                <my:DataGridCheckBoxColumn HeaderTemplate="{StaticResource DataGridColumnHeaderStyle}" Header="Add" Binding="{Binding Path=ADD}" Width="60" >
                                </my:DataGridCheckBoxColumn>
     now what exactly my problem is if i select one check box automatically deselect another check box means in datagridcheckbox column only one check box is selected i want to select all check boxes or more than one
    please help me out from this problem
    thanks in advance
    Sunday, October 04, 2009 4:31 AM

All replies

  • Hi,
    Can you please check the following link:

    Multiselect DataGrid with checkbox

    Thanks
    Md. Nazmul Ahsan DIT, IADCS , CIS
    Sunday, October 04, 2009 6:29 AM
  • Hi chaitanyanarne,

    Please set up the following example, you can check muliple datagrid checkbox cells at the same time.

        public partial class Window1 : Window
        {
            public Window1()
            {
                InitializeComponent();
                ObservableCollection<CustomObject> list = new ObservableCollection<CustomObject>() { new CustomObject() { Name="AA", Add=true},
                                                                                                     new CustomObject() { Name="BB", Add=true},
                                                                                                     new CustomObject() { Name="CC", Add=false},   
                                                                                                    };
                this.dataGrid1.DataContext = list;
                 
            }
        }
        public class CustomObject : INotifyPropertyChanged
        {
            private string name;
            public string Name
            {
                get
                {
                    return name;
                }
                set
                {
                    if (value != name)
                    {
                        name = value;
                        OnPropertyChanged("Name");
                    }
                }
            }
            private bool add;
            public bool Add
            {
                get
                {
                    return add;
                }
                set
                {
                    if (value != add)
                    {
                        add = value;
                        OnPropertyChanged("Add");
                    }
                }
            }
            #region INotifyPropertyChanged Members
            public event PropertyChangedEventHandler PropertyChanged;
            #endregion
            void OnPropertyChanged(string name)
            {
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(name));
                }
            }
        }
        <Grid>
            <my:DataGrid Margin="12" Name="dataGrid1" AutoGenerateColumns="False" ItemsSource="{Binding .,Converter = {StaticResource con}}">
                <my:DataGrid.Columns>
                    <my:DataGridTextColumn Header="AA" Binding="{Binding Name}"></my:DataGridTextColumn>
                    <my:DataGridCheckBoxColumn Header="BB" Binding="{Binding Add}">
                    </my:DataGridCheckBoxColumn>
                </my:DataGrid.Columns>
            </my:DataGrid>
        </Grid>

    Let me know if there's any problem.

    Best regards,
    Bruce Zhou


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, October 06, 2009 6:35 AM
  • Hi,

    I have the same problem. If I select one checkbox in Datagrid, the other one is automatically getting deselected which I don't want to happen.

    Also how can I add checkbox in the header column also, so that if I select that checkbox all the checkboxes in the Datagrid will be selected by default.

    Here is my XAML

    I really appreciate any kind of help.

    <sdk:DataGrid x:Name="dataGrid" ItemsSource="{Binding Test}" HorizontalAlignment="Stretch"VerticalAlignment="Top" Margin="4" FontSize="14" AutoGenerateColumns="False" CanUserReorderColumns="False" SelectionMode="Single">

    <sdk:DataGrid.Columns>

    <sdk:DataGridCheckBoxColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" IsReadOnly="False" Width="Auto" Binding="{Binding IsNew, Mode=TwoWay}" IsThreeState="False" />

    </sdk:DataGrid.Columns>

    </sdk:DataGrid>

     

    Thanks in advance.

    Thursday, January 27, 2011 10:37 PM
  • More Info.

    I am working on

    http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk: Datagrid in Silverlight 4 with MVVM framework.

    Thanks!

    Thursday, January 27, 2011 10:40 PM