This is a migrated thread and some comments may be shown as answers.

Checkbox filter within Gridview

16 Answers 479 Views
GridView
This is a migrated thread and some comments may be shown as answers.
jerry
Top achievements
Rank 1
jerry asked on 23 Apr 2009, 02:28 PM
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

16 Answers, 1 is accepted

Sort by
0
gerbrand
Top achievements
Rank 2
answered on 23 Apr 2009, 02:46 PM
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.
0
Jack
Telerik team
answered on 23 Apr 2009, 02:57 PM
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.
0
jerry
Top achievements
Rank 1
answered on 23 Apr 2009, 03:44 PM
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
0
Jack
Telerik team
answered on 24 Apr 2009, 03:24 PM
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.
0
jerry
Top achievements
Rank 1
answered on 24 Apr 2009, 03:36 PM
Jack,
Thank you so much.  Your post gave me and idea to just hide the column until it needs to be displayed.

Thank you
0
Jack
Telerik team
answered on 27 Apr 2009, 06:58 AM
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.
0
jerry
Top achievements
Rank 1
answered on 28 Apr 2009, 07:07 PM
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? 
0
Jack
Telerik team
answered on 29 Apr 2009, 09:15 AM
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.
0
jerry
Top achievements
Rank 1
answered on 01 May 2009, 12:32 PM
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
0
Deyan
Telerik team
answered on 06 May 2009, 08:01 AM
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.
0
jerry
Top achievements
Rank 1
answered on 06 May 2009, 01:14 PM
Deyan,
no problem thanks for the help.

Jerry
0
Jack
Telerik team
answered on 07 May 2009, 01:13 PM
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.
0
jerry
Top achievements
Rank 1
answered on 11 May 2009, 02:14 PM
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
0
Jack
Telerik team
answered on 11 May 2009, 03:19 PM
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.
0
jerry
Top achievements
Rank 1
answered on 11 May 2009, 03:36 PM
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
0
Jack
Telerik team
answered on 12 May 2009, 02:46 PM
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.
Tags
GridView
Asked by
jerry
Top achievements
Rank 1
Answers by
gerbrand
Top achievements
Rank 2
Jack
Telerik team
jerry
Top achievements
Rank 1
Deyan
Telerik team
Share this question
or