WPF DataGrid Check/Uncheck All Functionality-VBForums
Results 1 to 4 of 4

Thread: WPF DataGrid Check/Uncheck All Functionality

  1. #1

    Thread Starter
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    1,868

    WPF DataGrid Check/Uncheck All Functionality

    Here's a simple application I wrote before on how to add a checkbox with check/unchecked all functionality to a WPF DataGrid using DataGridTemplateColumnHeader.


    To run the application, perform steps below.
    1. ProductsSQL.sql
    - Change the target database of the script and execute. You may enter dummy records as well.
    2. App.config
    - Update the connection string attribute with your database and server settings

    Cheers!

    Name:  Checkall.png
Views: 851
Size:  34.5 KB

    Name:  Unchecked.png
Views: 847
Size:  30.7 KB
    Attached Files Attached Files
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: My Blog | GitHub Repo | ASP Snippets | CodeASP.net
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  2. #2
    Addicted Member
    Join Date
    Feb 2014
    Posts
    153

    Re: WPF DataGrid Check/Uncheck All Functionality

    KGComputers

    if uncheck 5 from 100 is there any way to loop throw checked only

    pessdo code

    if is checked then
    update table
    else
    {
    }

  3. #3
    Addicted Member
    Join Date
    Feb 2014
    Posts
    153

    Re: WPF DataGrid Check/Uncheck All Functionality

    this error appear

    An unhandled exception of type 'System.InvalidCastException' occurred in WpfDatagridCheckAllHeader.exe

    Additional information: Unable to cast object of type '<>f__AnonymousType0`2[System.String,System.String]' to type 'System.Data.DataRowView'.

    in this code
    DataRowView rv = (DataRowView)r.Item;

    Code:
     private void SetCheckbox(IEnumerable<DataGridRow> row, bool value)
            {
                
                foreach (DataGridRow r in row)
                {
    
                    DataRowView rv = (DataRowView)r.Item;
                    foreach (DataGridColumn column in dgProducts.Columns)
                    {
                        if (column.GetType().Equals(typeof(DataGridTemplateColumn)))
                        {
                            rv.Row["Discontinue"] = value;
    
                            //LINQ or Database Method to Update Product discontinue status
                            Connections.UpdateProductDiscontinue(value, rv.Row["productname"].ToString());
                        }
                    }
                }

  4. #4

    Thread Starter
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    1,868

    Re: WPF DataGrid Check/Uncheck All Functionality

    Try checking r.Item if it's not null.

    C# Code:
    1. if(r.item != null)
    2. {
    3.     DataRowView rv = (DataRowView)r.Item;
    4.     foreach (DataGridColumn column in dgProducts.Columns)
    5.        {
    6.           //...
    7.        }
    8. }
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: My Blog | GitHub Repo | ASP Snippets | CodeASP.net
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.