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

Filter Row Text Cells

3 Answers 177 Views
VirtualGrid
This is a migrated thread and some comments may be shown as answers.
Saji
Top achievements
Rank 1
Saji asked on 07 Dec 2016, 03:29 PM

Hello,

My company needs filter row to look like the attached image. Instead of the filter textbox to appear when user clicks on the filter cell, they want it always visible and also no filter icon visible. Is there way to achieve this in VirtualGrid ? Your assistance is greatly appreaciated.

Thank you,

Saji.

3 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 08 Dec 2016, 12:46 PM
Hello Saji,

Thank you for writing.  

RadVirtualGrid supports data filtering. Set the RadVirtualGrid.AllowFiltering property to true. Additional information is available here: http://docs.telerik.com/devtools/winforms/virtualgrid/filtering/filtering

Due to performance considerations and to avoid visual glitches when using controls (RadTextBoxEditor hosts the MS TextBox) in grid cells, RadVirtualGrid, similar to RadGridView, is designed to support editing mechanism. That is why I would recommend you to hide the filter button and the filter operator for the VirtualGridFilterCellElement in the CellFormatting event. The editor will be activated immediately after clicking the filter cell. Thus, you don't need a permanent editor actually: 
private void radVirtualGrid1_CellFormatting(object sender, Telerik.WinControls.UI.VirtualGridCellElementEventArgs e)
{
    if (e.CellElement.RowIndex == RadVirtualGrid.FilterRowIndex)
    {
        VirtualGridFilterCellElement filterCell = e.CellElement as VirtualGridFilterCellElement;
        if (filterCell!=null)
        {
            filterCell.FilterButton.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
            filterCell.FilterOperatorText.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
        }
    }
}

However, considering the provided information, you can create custom cells in RadVirtualGrid with the desired nested elements. The following help article demonstrates a approach: http://docs.telerik.com/devtools/winforms/virtualgrid/cells/creating-custom-cells

I hope this information helps. Should you have further questions I would be glad to help.

Regards,
Dess
Telerik by Progress
Telerik UI for WinForms is ready for Visual Studio 2017 RC! Learn more.
0
Saji
Top achievements
Rank 1
answered on 09 Dec 2016, 04:57 PM

Dess,

I like your approach. So I created a Filter textbox element (code far down below) . In the CreateCellElement event of the grid, I added this code:

        private void Grid_CreateCellElement(object sender, VirtualGridCreateCellEventArgs e)
        {
            if (e.RowIndex == RadVirtualGrid.FilterRowIndex)
            {
                e.CellElement = new CoreVirtualGridFilterEntryBoxElement();
            }
        }

However how can I register this cell element only for the filter row. Grid.MasterViewInfo.RegisterCustomColumn() method only allows me to specify column index.

Please assist.

Saj.

 

-----------

-------------------------- Code -----------------------------------

    public class CoreVirtualGridFilterEntryBoxElement : VirtualGridCellElement
    {
        private RadTextBoxElement textBox;
        protected override void CreateChildElements()
        {
            base.CreateChildElements();
            this.textBox = new RadTextBoxElement();
            this.Children.Add(textBox);
        }
        protected override void UpdateInfo(VirtualGridCellValueNeededEventArgs args)
        {
            base.UpdateInfo(args);
            if (args.Value is string)
            {
                textBox.Text = args.Value.ToString();
            }
        }
        public override bool IsCompatible(int data, object context)
        {
            //return base.IsCompatible(data, context);
            var rowElement = context as VirtualGridFilterRowElement;
            return rowElement != null;
        }
        public override void Attach(int data, object context)
        {
            base.Attach(data, context);
            this.textBox.TextChanging += TextBox_TextChanging;
            this.textBox.TextChanged += TextBox_TextChanged;
        }
        public override void Detach()
        {
            this.textBox.TextChanging -= TextBox_TextChanging;
            this.textBox.TextChanged -= TextBox_TextChanged;
            base.Detach();
        }
        protected override SizeF ArrangeOverride(SizeF finalSize)
        {
            var size = base.ArrangeOverride(finalSize);
            this.textBox.Arrange(new RectangleF(0, 0, size.Width, size.Height));
            return size;
        }
        protected override Type ThemeEffectiveType
        {
            get
            {
                return typeof(VirtualGridCellElement);
            }
        }
        private void TextBox_TextChanged(object sender, EventArgs e)
        {
            this.TableElement.GridElement.SetCellValue(textBox.Text, this.RowIndex, this.ColumnIndex, this.ViewInfo);
        }
        private void TextBox_TextChanging(object sender, Telerik.WinControls.TextChangingEventArgs e)
        {
        }
    }

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 12 Dec 2016, 07:48 AM
Hello Saji, 

Thank you for writing back. 

The IsCompatible method of the custom cell element controls for which rows the custom cell element is applicable. However, the RegisterCustomColumn method identifies only the column. Here is a modified code snippet demonstrating how to create custom filter cell element only for the third column in RadVirtualGrid:
public RadForm1()
{
    InitializeComponent();
 
    this.radVirtualGrid1.RowCount = 100;
    this.radVirtualGrid1.ColumnCount = 5;
    this.radVirtualGrid1.CellValueNeeded += radVirtualGrid1_CellValueNeeded;
     
    this.radVirtualGrid1.CreateCellElement += radVirtualGrid1_CreateCellElement;
    this.radVirtualGrid1.MasterViewInfo.RegisterCustomColumn(3);
}
 
private void radVirtualGrid1_CreateCellElement(object sender, VirtualGridCreateCellEventArgs e)
{
    if (e.RowIndex == RadVirtualGrid.FilterRowIndex)
    {
        if (e.ColumnIndex == 3)
        {
            e.CellElement = new CoreVirtualGridFilterEntryBoxElement();
        }
    }
}
 
public class CoreVirtualGridFilterEntryBoxElement : VirtualGridFilterCellElement
{
    private RadTextBoxControlElement textBox;
 
    protected override void CreateChildElements()
    {
        base.CreateChildElements();
        this.textBox = new RadTextBoxControlElement();
        this.Children.Add(textBox);
    }
 
    protected override void UpdateInfo(VirtualGridCellValueNeededEventArgs args)
    {
        base.UpdateInfo(args);
        if (args.Value is string)
        {
            textBox.Text = args.Value.ToString();
        }
    }
 
    public override bool IsCompatible(int data, object context)
    {
        //return base.IsCompatible(data, context);
        var rowElement = context as VirtualGridFilterRowElement;
        return rowElement != null && data == 3;
    }
 
    public override void Attach(int data, object context)
    {
        base.Attach(data, context);
        this.textBox.TextChanging += TextBox_TextChanging;
        this.textBox.TextChanged += TextBox_TextChanged;
    }
 
    public override void Detach()
    {
        this.textBox.TextChanging -= TextBox_TextChanging;
        this.textBox.TextChanged -= TextBox_TextChanged;
        base.Detach();
    }
 
    protected override SizeF ArrangeOverride(SizeF finalSize)
    {
        var size = base.ArrangeOverride(finalSize);
        this.textBox.Arrange(new RectangleF(0, 0, size.Width, size.Height));
        return size;
    }
 
    protected override Type ThemeEffectiveType
    {
        get
        {
            return typeof(VirtualGridCellElement);
        }
    }
 
    private void TextBox_TextChanged(object sender, EventArgs e)
    {
        this.TableElement.GridElement.SetCellValue(textBox.Text, this.RowIndex, this.ColumnIndex, this.ViewInfo);
    }
 
    private void TextBox_TextChanging(object sender, Telerik.WinControls.TextChangingEventArgs e)
    {
    }
}
 
private void radVirtualGrid1_CellValueNeeded(object sender, Telerik.WinControls.UI.VirtualGridCellValueNeededEventArgs e)
{
    e.Value = "Data" + e.RowIndex + "." + e.ColumnIndex;
}

I hope this information helps. If you have any additional questions, please let me know. 

Regards,
Dess
Telerik by Progress
Telerik UI for WinForms is ready for Visual Studio 2017 RC! Learn more.
Tags
VirtualGrid
Asked by
Saji
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Saji
Top achievements
Rank 1
Share this question
or