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

GridView highlighting the matching rows on Filter.

6 Answers 229 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Vishnu Ram Kumar
Top achievements
Rank 1
Vishnu Ram Kumar asked on 15 Dec 2009, 01:52 PM

Hello,

I have a Filter Row in my GridView's header. The normal behaviour of filter is to hide the unmatching rows.
But my requirement is to highlight the matching rows and unmatched rows will still be shown. I am using the following function to do that. I am trying to set the IsSelected Property of the matching records to true, which i hoped will highlight the row. But it is not doing that. Please help.

 public void ApplySelect(object sender)  
        {  
            try  
            {  
                var senderElement = sender as FrameworkElement;  
                FilterRowDescriptor newDescriptor = new FilterRowDescriptor();  
                newDescriptor.LogicalOperator = FilterCompositionLogicalOperator.And;                  
                int idx=0;  
                foreach (MainPage.BuyHeadView bhRow in this.grid.Items)  
                {  
                    TextBox txt = senderElement as TextBox;  
                    if (bhRow.CampaignName.StartsWith(txt.Text.Trim()))  
                    {  
                        this.grid.Records[idx].IsSelected = true;  
                    }  
                    idx++;                      
                }  
                  
                //headerRow.ParentGrid.FilterDescriptors.Remove(headerRow.ParentGrid.FilterDescriptors.Where(fd => fd is FilterRowDescriptor).FirstOrDefault());  
                //headerRow.ParentGrid.FilterDescriptors.Add(newDescriptor);  
            }  
            catch  
            {  
            }  
        } 

6 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 16 Dec 2009, 07:52 AM
Hi,

 Can you post more info about your grid version?


Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Vishnu Ram Kumar
Top achievements
Rank 1
answered on 16 Dec 2009, 01:36 PM
Hello

The Version i am using is 2009.2.1005.35.
I got this version through one of the example downloads.

Thanks
Vishnu.
0
Stefan Dobrev
Telerik team
answered on 22 Dec 2009, 10:13 AM
Hi Vishnu,

What you can implement is to create a QueryableCollectionView that will be used for the filtering instead of the one in the grid. In the custom filter row code you will add the filter descriptor to this custom collection view filter descriptors. After that you can foreach this collection and add all the items to the selected items of the grid.

Also my advice is to upgrade your binaries to the 2009 Q3 SP1 version, because there are numerous improvements in the latest version of the RadGridView for WPF.

Kind regards,
Stefan Dobrev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Vishnu Ram Kumar
Top achievements
Rank 1
answered on 28 Dec 2009, 04:45 AM
Hi ,

The Solution you gave worked. Thank you.
I am now using the DLLs of Q3 release.

But now, i am getting another problem. The RadGridview i was working on has two columns. I wanted to have the filter textboxes in all the column's headers. But it always gives me the filter textbox only on the first column. As i debugged, i found that the problem is with the Cell Count. The Count of cells of the Header Row is always reuturned as 1. In the following code snippet 

var cells = row.ChildrenOfType<GridViewHeaderCell>();   returns only one header cell. whereas i have 2 cells. Please suggest the solution as soon as possible.

private void InitializeFilters(GridViewHeaderRow row)  
        {  
            row.ChildrenOfType<FrameworkElement>().Where(fe => fe.Height == 26).ToList().ForEach(fe => fe.Height = double.NaN);  
            row.ChildrenOfType<GridViewHeaderCell>().ToList().ForEach(fe => fe.Height = 55);  
 
            // Get all header cells.  
            var cells = row.ChildrenOfType<GridViewHeaderCell>();   
            //var cells = row.Cells;  
 
            foreach (GridViewHeaderCell cell in cells)  
            {  
                AlignmentContentPresenter content = cell.ChildrenOfType<AlignmentContentPresenter>().FirstOrDefault();  
                if (cell.ChildrenOfType<TextBox>().Count <= 0)  
                    this.AddFilterRowElements(content, cell);  
            }  
        } 

 

private void AddFilterRowElements(AlignmentContentPresenter elementsHost, GridViewHeaderCell cell)

 

{

 

    if (elementsHost == null || cell == null)

 

 

    return;

 

 

    var column = cell.Column as GridViewDataColumn;

 

 

    if (column == null)

 

 

    return;

 

 

    // Hide default filter icon.

 

    cell.ChildrenOfType<

FilteringDropDown>().ToList().ForEach(fd => fd.Visibility = Visibility.Collapsed);

 

 

    // Insert two row definitions

 

 

    Grid parentGrid = elementsHost.ParentOfType<Grid>();

 

    parentGrid.RowDefinitions.Add(

new RowDefinition());

 

    parentGrid.RowDefinitions.Add(

new RowDefinition());

 

 

    FrameworkElement element = null;

 

 

 

    //if (column.DataType == typeof(System.String))

 

 

    //{

 

 

    TextBox stringBox = new TextBox();

 

    stringBox.TextChanged +=

new TextChangedEventHandler(TextBox_TextChanged);

 

    element = stringBox;

 

    //}

 

 

    Grid.SetRow(element, parentGrid.RowDefinitions.Count - 1);

 

    parentGrid.Children.Add(element);

}


Thanks,
Vishnu
0
Stefan Dobrev
Telerik team
answered on 04 Jan 2010, 09:08 AM
Hi Vishnu Ram Kumar,

You can use the Header property of the Column to insert your filtering text box. For example you can specify a header which looks like this:
<telerik:RadGridView>
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn  DataMemberBinding="{Binding TheNameOfTheProperty}">
            <telerik:GridViewDataColumn.Header>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="Put your header text here" />
                    <TextBox TextChanged="TextBox_TextChanged" />
                </Grid>
            </telerik:GridViewDataColumn.Header>
        </telerik:GridViewDataColumn>
    </telerik:RadGridView.Columns>               
</telerik:RadGridView>

Hope this helps,
Stefan Dobrev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Vishnu Ram Kumar
Top achievements
Rank 1
answered on 07 Jan 2010, 10:25 AM
Hi Stefan,

I did as you said to do. But it still does not work. The problem is i have to handle the TextBox_TextChanged 
in another class. If i code it in xaml i will have to handle it in xaml.cs, which i cant.

I have uploaded the entire code at the following support ticket (as i cant do it in the post).
Kidnly look into the code and suggest a solution as soon as possible.
http://www.telerik.com/account/support-tickets/view-ticket.aspx?threadid=270403

Thanks,
Vishnu
Tags
GridView
Asked by
Vishnu Ram Kumar
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Vishnu Ram Kumar
Top achievements
Rank 1
Stefan Dobrev
Telerik team
Share this question
or