Checkbox filter within Gridview

17 posts, 0 answers
  1. jerry
    jerry avatar
    103 posts
    Member since:
    Feb 2008

    Posted 23 Apr 2009 Link to this post

    Question #1
    When adding a checkbox column to a gridview and when I turn on the filter option of the grid there is a checkbox that shows up as part of the filter.  How can I turn that into a select all checkbox instead of filtering on it?  Is there a better alternative to doing this?

    Question #2
    How come when I add a checkbox to my gridview before filling the gridview with data it just shows the checkbox and it doesn't look right/good is there a way to just have a clear grid or at least make it look better? 



    Thank You
  2. gerbrand
    gerbrand avatar
    78 posts
    Member since:
    Mar 2009

    Posted 23 Apr 2009 Link to this post

    Hi Jerry,

    For you first question I think you need to check out this post in the knowledge base
    Should help you.

    Second question I have no idea.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 23 Apr 2009 Link to this post

    Gerbrand, thank you for pointing this out. You are faster than me :)

    Jerry, to your second question: Could you please describe in more detail the expected appearance in this case. I will be glad to help you further.

    All the best,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. jerry
    jerry avatar
    103 posts
    Member since:
    Feb 2008

    Posted 23 Apr 2009 Link to this post

    Thanks fellas for the quick help.

    Jack,
    when I load my windows form in the load event I add a checkbox column to two different gridviews.  The grids don't populate till after the form loads and the user selects different values in drop downs.  While the grids are empty I have just a single checkbox showing in both grids just sitting there.  I had to disable the filter option for that column so the user doesn't click it and have the app crash.  I'm just trying to find a way to hide it until the data fills.

    Thanks again i'm going to go work on question 1.  Thanks

    Jerry
  6. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 24 Apr 2009 Link to this post

    Hi Jerry,

    Maybe the easiest way is to set the DataSource and add columns when there is a data. If this is not possible, you can hide all system rows. Set the EnableFiltering, ShowColumnHeaders and AllowAddNewRow to false and enable them after loading the data. Here is an example:

    this.radGridView1.MasterGridViewTemplate.EnableFiltering = false
    this.radGridView1.MasterGridViewTemplate.ShowColumnHeaders = false
    this.radGridView1.MasterGridViewTemplate.AllowAddNewRow = false
     
    // ... 
     
    this.radGridView1.MasterGridViewTemplate.EnableFiltering = true
    this.radGridView1.MasterGridViewTemplate.ShowColumnHeaders = true
    this.radGridView1.MasterGridViewTemplate.AllowAddNewRow = true

    I hope this helps. Should you have any other questions, don't hesitate to ask.

    All the best,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. jerry
    jerry avatar
    103 posts
    Member since:
    Feb 2008

    Posted 24 Apr 2009 Link to this post

    Jack,
    Thank you so much.  Your post gave me and idea to just hide the column until it needs to be displayed.

    Thank you
  8. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 27 Apr 2009 Link to this post

    Jerry, I am glad to hear that. If you have any other questions, feel free to write us.

    Best wishes,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  9. jerry
    jerry avatar
    103 posts
    Member since:
    Feb 2008

    Posted 28 Apr 2009 Link to this post

    Jack,
    I went through the steps that gerbrand  posted the link too and I'm still having an issue.  Following those steps puts a checkbox in the header.  I still have a checkbox in the filter section.  How can I remove the checkbox from the filter section?  What I have now is 2 checkboxes on top of each other 1 in the header 1 in the filter and it looks very odd.  How can I remove the filter one? 
  10. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 29 Apr 2009 Link to this post

    Hi jerry,

    Please handle the ViewCellFormatting event to hide the checkbox inside a filter cell. Here is a sample:

    void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e) 
        if (e.CellElement.RowInfo is GridViewFilteringRowInfo && e.CellElement.ColumnInfo.HeaderText == "Option1"
        { 
            e.CellElement.Children[0].Visibility = ElementVisibility.Collapsed; 
        } 

    If you need further assistance, I will be glad to help.

    Sincerely yours,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  11. jerry
    jerry avatar
    103 posts
    Member since:
    Feb 2008

    Posted 01 May 2009 Link to this post

    Jack,
    Thank you for the code.  I'm having one other issue with this check all.  When each checkbox is checked the 

    ValueChanged event for that grid fires.  Within that event I have this piece of code to check to make sure it's a checkbox that is being changed

    if (this.GVVariables.ActiveEditor is RadCheckBoxEditor) 

    When I check the checkboxes manually this works correctly but with the select all the this.GVTables.ActiveEditor is null. 
    How come it is null? 
    I need data from each row to store in lists to generate reports.  Is there a different way to get the column values I need with this event?
    Here is my code for pulling data from a column with my ValueChanged event.

    string sID = GVVariables.Rows[this.GVVariables.CurrentCell.RowIndex].Cells[1].Value.ToString(); 

    Thank You
    Jerry
  12. Deyan
    Admin
    Deyan avatar
    2041 posts

    Posted 06 May 2009 Link to this post

    Hi Jerry,

    We need some more time to review this case. Please, expect a reply shortly.

    Sincerely yours,
    Deyan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  13. jerry
    jerry avatar
    103 posts
    Member since:
    Feb 2008

    Posted 06 May 2009 Link to this post

    Deyan,
    no problem thanks for the help.

    Jerry
  14. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 07 May 2009 Link to this post

    Hello Jerry,

    The checkbox inside the header cell is not part from the editors system of RadGridView. Because of this the ActiveEditor property is null. You can get the desired checkbox values by iterating over the grid rows. Here is a sample:

    foreach (GridViewDataRowInfo row in GVVariables.Rows) 
        string value = row.Cells[1].Value.ToString(); 
        // ... 

    It would be better to use the following syntax when accessing the checkbox value inside ValueChanged event:

     
    this.GVVariables.CurrentRow.Cells[1].Value.ToString();  
     

    I hope this helps. If you have more questions, don't hesitate to ask.

    Sincerely yours,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  15. jerry
    jerry avatar
    103 posts
    Member since:
    Feb 2008

    Posted 11 May 2009 Link to this post

    Jack,
    I have two grids and one fills based on the checking of rows in the first grid.
    So everytime a row in the first grid is checked I have to query a DB and return the results but then I have to go through the rows and check the ones that were checked already.  When I do this code to check the specific row

    GVVariables.Rows[i].Cells[0].Value = 1;

    the valuechanged event for this grid fires and when I do the


    if

     

    (this.GVVariables.ActiveEditor is RadCheckBoxEditor)

     

    or
    this.GVVariables.CurrentRow.Cells[1].Value.ToString();  

    I get nothing.  How can I  make sure I have access to that row i'm checking?

    Thank You
    Jerry
  16. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 11 May 2009 Link to this post

    Hello Jerry,

    Thank you for staying with us.

    When using the UI to change the cell value there is an ActiveEditor associated with that cell. However, when using the Value property, the ActiveEditor is null.  I am not sure if I understand correctly your last question. Please send a sample application and describe the desired behavior in more details. I will be glad to help you further.

    I am looking forward to your reply.

    Sincerely yours,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  17. jerry
    jerry avatar
    103 posts
    Member since:
    Feb 2008

    Posted 11 May 2009 Link to this post

    Jack,
    I can't send a sample app it would take me too long to make one.  I will try and describe it better.
    I have two grids.  We can call them gridTable and gridCol.
    When I user checks a row within gridTable I query a DB and list all the columns for the selected table in gridCol.
    The user can select as many tables are he wants and gridCol will populate all the columns.  Both grids have a checkbox column because the user will select which columns he wants to use to generate a report.  Where my issue is happening is when the user unchecks a row within gridTable.  I have a list that holds the ids of the tables and columns that were checked. When a user unchecks a table I must remove all the rows from gridCol for the unchecked table.
    Since I have to do a query to get back all the columns for the checked rows for gridTable I clear our gridCol then repopulate then I cycle through and programically check all the rows within gridCol that were checked before the user unchecked a row in gridTable.  When I do this the valuechange event fires this is where i'm losing the active editor.  It's when I programically set the checked rows back to being checked after gridCol is re-populated.  Does this make more sense?


    Thanks again for your help
    Jerry
  18. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 12 May 2009 Link to this post

    Hi jerry,

    Thank you for this clarification.

    I think we are getting closer to resolving this.

    The ValueChanged event is fired when a cell in RadGridView changes its value. When this happens through code (e.g when setting directly the Value property), there is no ActiveEditor and the sender argument contains a GridViewCellInfo class that represents the changed cell. However, when using the UI the sender argument contains the visual cell element and the ActiveEditor contains RadCheckBoxEditor. The actual cell value is contained in the editor in this case. So, you should check the ActiveEditor.Value property. Here is a sample:

    void radGridView1_ValueChanged(object sender, EventArgs e) 
        GridViewCellInfo cellInfo = sender as GridViewCellInfo; 
        if (cellInfo != null
        { 
            if (cellInfo.ColumnInfo.FieldName == "Option1"
            { 
                int count = 0; 
                foreach (GridViewDataRowInfo row in this.radGridView1.Rows) 
                { 
                    if ((bool)row.Cells["Option1"].Value && row != this.radGridView1.CurrentRow) 
                    { 
                        count++; 
                    } 
                } 
            } 
        } 
        else if (this.radGridView1.ActiveEditor is RadCheckBoxEditor) 
        { 
            int count = 0; 
            foreach (GridViewDataRowInfo row in this.radGridView1.Rows) 
            { 
                if ((bool)row.Cells["Option1"].Value && row != this.radGridView1.CurrentRow) 
                { 
                    count++; 
                } 
            } 
            if ((bool)this.radGridView1.ActiveEditor.Value) 
            { 
                count++; 
            } 
        }     

    I hope this helps. If you have further questions, please don't hesitate to ask.

    Kind regards,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top
UI for WinForms is Visual Studio 2017 Ready