0

I have implemented GRIDCONTROL in which I have added a TABLEVIEW which contains Columns say NAME, AGE, SALARY . I'am fetching the data from Database and filling the columns accordingly. Now I want to add a Checkbox to each row so that if I could select two rows at a time and fetch corresponding data. How to implement the Checkbox?

I am Using DEVEXPRESS controls

<GridControl Name="gridControl1">
    <GridControl.View>
        <TableView x:Name="view" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  />
    </GridControl.View>
    <GridControl.Columns>
        <GridColumn FieldName="Name"  Name="Name"  Width="120" Header="Name"/>
        <GridColumn FieldName="Age"  Name="Age"  Width="120" Header="Age"/>                
        <GridColumn FieldName="Salary"  Name="Salary"  Width="120" Header="Salary" />                
    <GridControl.Columns>
<GridControl>

Now I want to add Checkboxes for each entry of the row, So that if the select that checkbox I could fetch all the data corresponding to that Row.

harin04
  • 271
  • 5
  • 16

1 Answers1

0

I'm using this approach for a similar application. A seperate column is used to select a person. There is also a checkbox in the header of that column that will select/deselect all people.

ViewModel

private ObservableCollection<PersonModel> _peopleCollection;
public ObservableCollection<PersonModel> PeopleCollection
{
        get { return _peopleCollection; }
        set
        {
            _peopleCollection = value;
            RaisePropertyChanged("PeopleCollection");
        }
    }

private void initPeople()
    {
        foreach (var person in PeopleCollection)
        {             
            person.PropertyChanged += PersonOnPropertyChanged;
       }
    }

private void PersonOnPropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs)
    {
        if(propertyChangedEventArgs.PropertyName == "IsPersonSelected")
        {
    //Handle checked/unchecked person

        }
    }


private bool _allPersonsSelected
    public bool AllPersonsSelected
    {
        get { return _allPersonsSelected; }
        set
        {
            _allPersonsSelected= value;
            RaisePropertyChanged("AllPersonsSelected");

            if (value)
                SelectRows();
            else
            {
                DeselectRows();
            }
        }
    }

    public void SelectRows()
    {
        foreach (var record in PeopleCollection)
            record.IsPersonSelected = true;
    }

    public void DeselectRows()
    {
        foreach (var record in PeopleCollection)
            record.IsPersonSelected = false;
    }

}

Here is the grid xaml from the view

<dxg:GridControl ItemsSource="{Binding Path=PeopleCollection}">
            <dxg:GridControl.View>
                <dxg:TableView>
                </dxg:TableView>
            </dxg:GridControl.View>
            <dxg:GridControl.Columns>
                <dxg:GridColumn FieldName="IsPersonSelected"
                                HorizontalHeaderContentAlignment="Left">
                    <dxg:GridColumn.Header>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock>Selected</TextBlock>
                            <dxe:CheckEdit EditValue="{Binding Path=AllPersonsSelected}"
                                           Margin="10,0,0,0" />
                        </StackPanel>
                    </dxg:GridColumn.Header>
                </dxg:GridColumn>
                <dxg:GridColumn FieldName="Name" Header="Name"/>
                <dxg:GridColumn FieldName="Age" Header="Age"/>
            </dxg:GridControl.Columns>
        </dxg:GridControl>
keft
  • 266
  • 1
  • 8