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

Datasource set to dataTable no filter row showing

10 Answers 278 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dave Galligher
Top achievements
Rank 2
Dave Galligher asked on 18 Feb 2011, 12:50 AM
I've got a radgridview control hosted in a winforms application that is bound to a datatable via: "radGridView1.DataSource = dataTable". The property ShowFilteringRow is set to true, but when the data is shown - no filtering row appears.

How can I get the filtering row to show the radgridview is bound to a datasource.

And before it is suggested, yes I could filter the data before the datatable is bound, but there could be literally thousands or records in the table and the user may want to filter the information further once the information is displayed. An example, I pull information from a vendor table for the state of Idaho (1000 records).... once the information is displayed the user wants to filter by Boise (250 records). They may want to filter further based on a value in another column that may take the count down from 250 to 10 records. You get the idea.

Yes they can use the column ordering values, but that doesn't work. The idea later is to export the information to XML based on the filtered selection explained above.

Thank you in advance for your assistance.

10 Answers, 1 is accepted

Sort by
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 18 Feb 2011, 08:38 AM
Hello Dave,

Apart from ShowFilteringRow, you also need to enable filtering.
RadGridView1.EnableFiltering = True
RadGridView1.ShowFilteringRow = True
The filtering row will show only when both are set to true.
Hope that helps
Richard
0
Dave Galligher
Top achievements
Rank 2
answered on 18 Feb 2011, 09:32 PM
Thank you, that worked. It brings me to an additional question not related to original thread. Hoping there is a similar simple answer.

How to autosize the column widths once the datasource property is set to the data table? Currently users need to click on individual columns after data is loaded. Tried setting: radgridview.Autosize = true, and it slows down the app, it almost seems like it is locked up. Thinking maybe I need to add a BeginUpdate before the Autosize and EndUpdate after the Autosize, would appreciate your feedback.

Thank you again.
Dave
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 19 Feb 2011, 02:17 AM
Hello Dave,

To BestFit the columns, you can use the following code:

First make sur that your grid AutoSizeColumnsMode is set to none
this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.None;

and then call BestFit on each column
using (this.radGridView1.DeferRefresh())
{
    foreach (GridViewDataColumn column in this.radGridView1.Columns)
    { column.BestFit(); }            
}

Hope that helps.
Please remember to mark answers so other can find the solution too
thanks
Richard
0
Dave Galligher
Top achievements
Rank 2
answered on 20 Feb 2011, 07:44 PM
Thank you Richard, that worked.
0
Richard Slade
Top achievements
Rank 2
answered on 20 Feb 2011, 09:32 PM
Glad I could help, Dave
Richard
0
Dave Galligher
Top achievements
Rank 2
answered on 20 Feb 2011, 10:25 PM
Hopefully, the last issue on this databinding for the grid: Alternating row color not working once the data source is set. Datasource could easily have hundreds of rows. I'm currently handling the row color like this:

private void radGridView1_RowFormatting(object sender, RowFormattingEventArgs e)
        {
            if (e.RowElement.IsOdd)
            {
                e.RowElement.DrawFill = true;
                e.RowElement.BackColor = Color.AliceBlue;
            }
            else
                e.RowElement.DrawFill = false;

        }                     

e.RowElement.IsOdd never get's fired on the RowFormatting after the datasource is set? Any ideas?

As always, thank you in advance,
Dave
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 20 Feb 2011, 10:37 PM
Hi Dave,

You could either simply set
this.radGridView1.EnableAlternatingRowColor = true;

or, for more control, you can find the odd/even numbers of the RowIndex in RowFormatting.
private void radGridView1_RowFormatting(object sender, RowFormattingEventArgs e)
{
    if (e.RowElement.RowInfo.Index % 2 != 0)
    {
        e.RowElement.DrawFill = true;
        e.RowElement.BackColor = Color.AliceBlue;
        e.RowElement.NumberOfColors = 1;
    }
    else
    {
        e.RowElement.ResetValue(LightVisualElement.DrawFillProperty);
        e.RowElement.ResetValue(LightVisualElement.BackColorProperty);
        e.RowElement.ResetValue(LightVisualElement.NumberOfColorsProperty);
    }
}

Hope that helps
Regards,
Richard
0
Dave Galligher
Top achievements
Rank 2
answered on 20 Feb 2011, 11:13 PM
Well, there was one other thing on the filtered row set, with data source set and filtered row set specified, I end up with a subset of records displayed. Example I start with 10, I filter further I end up with three rows. Now I want to export the information to an external file. Unlike other grids that are not bound by the Datasource when I walk through the rows, I only get the filtered set, but with a Datasource set, when I walk through the rows, I get all of the data regardless if they fall into the defined filter or not and they aren't showing.

I check for the visible state of the row and the information still get's passed:

 foreach (GridViewRowInfo row in radGridView1.Rows)
                {
                    sbLine.Clear();
                    nPos = 0;

                    if (row.IsVisible)                                              // always returns true, regardless of what is showing on grid.
                    {
...

The purpose of this is to allow the user only to export records that match their final criteria once the filtered is applied. In this case the StringBuilder sbLine is used to create information that goes into a comma delimited file.

Is there a collection of GridViewRowInfo rows that only apply to the rows showing when connecting to a data set? Row.IsVisible is always returning true regardless of what is being shown on the grid.

I've also tried additional properties like IsExpanded, Height, etc. but it seems the values are the same regardless of what the visiblity state is for the row. Obviously, there is something that is controlling if the row is shown or not because the filter row works great.

Any help will be appreciated. Thank you,
Dave
0
Richard Slade
Top achievements
Rank 2
answered on 20 Feb 2011, 11:39 PM
Hi Dave,

You need to look for this at the ChildRows collection. If you loop over the ChildRows you will just get those rows that are currently in the grid in this case.
foreach (GridViewRowInfo row in this.radGridView1.ChildRows)
{
    // do something with row
}

However, if you're exporting data, take a look at the grid export functions as this is really easy to use and has settings for setting conditions to export visible rows and columns, if you want to maintain the visual style etc..

ExportToExcelML
ExportToCSV
ExportToHTML
ExportToPDF

hope that helps
Richard
0
Dave Galligher
Top achievements
Rank 2
answered on 20 Feb 2011, 11:52 PM
I just figured it out. It needs to be tied to MasterView.Rows to ignore the other rows NOT .Rows. Thanks for your help.
Tags
GridView
Asked by
Dave Galligher
Top achievements
Rank 2
Answers by
Richard Slade
Top achievements
Rank 2
Dave Galligher
Top achievements
Rank 2
Share this question
or