Home Forums WPF controls Xceed DataGrid for WPF Binding to the Column Header Control

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #23392 |

    Please let me know how to achieve the following:

    There should be a checkbox in the header to check all and uncheck all.
    There should be checkboxes with individual records to select the records individually.
    The check all check box on the header should be checked if all the records are individually selected.
    There should be an external button outside the DataGrid by which we should be able to retrieve checked records.

    Thanks in advance

    Regards
    Sathanantham

    Imported from legacy forums. Posted by Satheesh (had 4983 views)

    User (Old forums)
    Member
    Post count: 23064

    the simple way is to add the checked column to your datasource
    You would have to create a datatemplate for a colummanagerrow cell which has a check box
    then catch the Ischeckedchanged event and then Check all rows in code with a loop through the datasource and check all the rows.
    If your select column is of type bool there should be a checkbox DataTemplate cell available
    if not it is simple to create one.

    then from any button you could loop through the datasource and get the checked records.

    (Best to keep the checked ability in your hands and not in the DataGridControl’s because of virtualization. You would not be able to retrieve the checked status of rows not currently visible.)

    (In creating a check box cell I would bind the IsChecked value directly to the bool columns value because if you use a celleditor and a check box you have to sometimes double click or triple click to get the correct result only one click on a checkbox should get)

    Imported from legacy forums. Posted by MiddleTommy (had 360 views)

    User (Old forums)
    Member
    Post count: 23064

    See this post on checkbox data template
    http://forums.xceed.com/forums/ShowPost.aspx?PostID=7799

    Imported from legacy forums. Posted by MiddleTommy (had 390 views)

    User (Old forums)
    Member
    Post count: 23064

    Dear MiddleTommy,

    Thank you for your kind reply.

    Could you provide me the sample code to check all rows in code with a loop through the datasource and check all the rows?

    Thanks in advance

    Regards
    Sathanantham

    Imported from legacy forums. Posted by Satheesh (had 310 views)

    User (Old forums)
    Member
    Post count: 23064

    What is your datasource?
    a DataView, ObservableCollection<T>?
    DataTable etc…

    Imported from legacy forums. Posted by MiddleTommy (had 301 views)

    User (Old forums)
    Member
    Post count: 23064

    Dear Tommy,

    It’s ObservableCollection<T>

    Regards
    Sathanantham

    Imported from legacy forums. Posted by Satheesh (had 345 views)

    User (Old forums)
    Member
    Post count: 23064

    Assuming T has a Checked Property bound to a Column in the grid.

    <code>
    ObservableCollection<CheckableObject> ocollection = new ObservableCollection<CheckableObject>;
    void button_Click(object sender, RoutedEventArgs e)
    {
    IEnumerator<CheckableObject> e = ocollection.GetEnumerator();
    while(e.MoveNext())
    {
    if(e.Current.Checked)
    {
    //do what you want with checked item
    }
    }
    }

    </code>

    If you have multiple types of objects in various grids you should create an interface like

    public interface ICheckable{Checked{get;}}

    then implement the interface in all your DataObjects
    if your code is still generic when you loop through the collection you have to use “where” to access the Checked property:

    public MyClass<T> where T:ICheckable

    Imported from legacy forums. Posted by MiddleTommy (had 399 views)

    User (Old forums)
    Member
    Post count: 23064

    Dear Tommy,

    Thanks a lot. It works fine.

    Regards
    Sathanantham

    Imported from legacy forums. Posted by Satheesh (had 6177 views)

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.