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

grid view filters

12 Answers 217 Views
GridView
This is a migrated thread and some comments may be shown as answers.
salini
Top achievements
Rank 1
salini asked on 16 Nov 2010, 08:04 AM
i m working on win froms
i need the code for the design attached
plz help me

12 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 18 Nov 2010, 01:23 PM
Hello salini,

Thank you for writing.

The code that you have requested can be found in our demo application solution. You can locate this solution at Start Menu >> Programs >> Telerik >> RadControls for WinForms[version] >> Open Sample C# or VB Solution in Visual Studio.

I hope you find this information helpful. If there is anything else I can assist you with, do not hesitate to contact me.
 
Kind regards,
Stefan
the Telerik team
See What's New in RadControls for WinForms in Q3 2010 on Wednesday, November 17, 11am Eastern Time: Register here>>
0
Fernando
Top achievements
Rank 1
answered on 18 Nov 2010, 04:05 PM
Sorry for my English first.
I have a RadGridView and all the filters work well only when the cell contents are a string of less than 20 characters, otherwise the result is a table returns me empty, if not my mistake or a constraint filtering.
appreciate your response


this is the code with which I fill my table

Dim table As DataTable = New DataTable
Dim adaptadorConexion As New Odbc.OdbcDataAdapter
adaptadorConexion = New Odbc.OdbcDataAdapter(SQLQuery, con)
adaptadorConexion.Fill(table)
RadGridView1.DataSource = table

con is my ODBC connection





0
Fernando
Top achievements
Rank 1
answered on 18 Nov 2010, 04:50 PM
Hi, I found the problem: the percentage% symbol, apparently is not supported and therefore not doing the filtering, I checked everything and hard that's the only alternative.
create a table and just kept rates so I do not accept filtered, believe there is a way to correct this?
0
salini
Top achievements
Rank 1
answered on 19 Nov 2010, 06:48 AM
thanks telerik
but still i am not able to find the code
.i am not able to find which code to be used from the given demos.can you give more details
0
Emanuel Varga
Top achievements
Rank 1
answered on 19 Nov 2010, 08:32 AM
Hello Salini,

Please take a look at the following example:
using System;
using System.ComponentModel;
using System.Windows.Forms;
using Telerik.WinControls.UI;
 
public partial class Form1 : Form
{
    private RadGridView radGridView1;
 
    public Form1()
    {
        InitializeComponent();
        this.Controls.Add(radGridView1 = new RadGridView());
        radGridView1.Dock = DockStyle.Fill;
        radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
 
        // enable filtering
        radGridView1.EnableFiltering = true;
        //hide the filtering row if we are using excel like filtering
        radGridView1.ShowFilteringRow = false;
        //show header cells buttons for the filter look described in the image
        radGridView1.ShowHeaderCellButtons = true;
    }
 
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        radGridView1.DataSource = new ObjectsCollection();
    }
}
 
public class ObjectsCollection : BindingList<Object1>
{
    public ObjectsCollection()
    {
        for (int i = 0; i < 10; i++)
        {
            this.Add(new Object1(i, "Object" + i));
        }
    }
}
 
public class Object1
{
    public int Id
    {
        get;
        set;
    }
 
    public string Name
    {
        get;
        set;
    }
 
    public Object1(int id, string name)
    {
        this.Id = id;
        this.Name = name;
    }
}

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
salini
Top achievements
Rank 1
answered on 19 Nov 2010, 02:00 PM
this code is showing error
"gridview doesn't contain definition for

ShowHeaderCellButtons


though i ve included the namespace

using

 

Telerik.WinControls.UI;

 

0
Emanuel Varga
Top achievements
Rank 1
answered on 19 Nov 2010, 02:02 PM
Hello salini,

Are you sure you are using the Q3 version of telerik controls?

This feature was just introduced in the latest release, if you are not using it, please install it and please try again.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
salini
Top achievements
Rank 1
answered on 19 Nov 2010, 02:09 PM
ok
i m using q2 version
anyways thanks

i have another doubt
my gridview is not showing default context menu
previously i disabled it and so i m not able to use that.
but now
i need to copy the contents of the selected cell to use it in the filter property for which i require it.

thanks in advance


0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 20 Nov 2010, 01:06 AM
Hello again Salini,

And you cannot enable it again?

You can just use it for the grid cells, something like this:
First enable the cell context menu and register for the context menu opening events, like so:
radGridView1.AllowCellContextMenu = true;
radGridView1.AllowColumnHeaderContextMenu = false;
radGridView1.ContextMenuOpening += new ContextMenuOpeningEventHandler(radGridView1_ContextMenuOpening);

After this, on the ContextMenuOpening just clear the items in the current context menu and create your own.
Here i am just creating the SaveMenuItem with the CurrentCell.Value as a tag, so you can access it on the MenuItem.Click event (you could also use on the MenuItem.Click event the radGridView1.CurrentCell.Value, mostly it's just a matter of preference):
void radGridView1_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
{
    var dataCell = e.ContextMenuProvider as GridDataCellElement;
    if (dataCell == null)
    {
        e.Cancel = true;
    }
 
    e.ContextMenu.Items.Clear();
    var copyItem = new RadMenuItem("Copy", dataCell.Value);
    copyItem.Click += new EventHandler(copyItem_Click);
    e.ContextMenu.Items.Add(copyItem);
}
 
void copyItem_Click(object sender, EventArgs e)
{
    var menuItem = sender as RadMenuItem;
    if (menuItem == null)
    {
        return;
    }
 
    var cellValue = menuItem.Tag;
 
    MessageBox.Show("The value of the cell is " + cellValue.ToString());
}

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
Stefan
Telerik team
answered on 23 Nov 2010, 04:43 PM
Hello salini,

Thank you for writing.

Please refer to Emanuel's suggestion in order to take advantage of the ContextMenu in RadGridView. 

I am not sure that your previous issue is being solved, please could you confirm that? If you need any further assistance we will be glad to help.
 
Greetings,
Stefan
the Telerik team
Get started with RadControls for WinForms with numerous videos and detailed documentation.
0
salini
Top achievements
Rank 1
answered on 24 Nov 2010, 07:41 AM
hi stefan
Firstly, I am sorry that i didn't reply

actually i couldn't solve that problem.
Copying is fine.
My question is how can I use the paste option on the gridview filters?

thanks for ur cooperation
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 25 Nov 2010, 10:55 AM
Hello Salini,

The easiest way to do this is to use the Clipboard.SetText(string) function to copy the cell's text to the clipboard and then you can easily paste it to the filter cell, either using the normal paste function or the Extra paste button I've added to the menu.

Please take a look the following full example:
using System;
using System.ComponentModel;
using System.Windows.Forms;
using Telerik.WinControls.UI;
 
public partial class Form1 : Form
{
    private RadGridView radGridView;
 
    public Form1()
    {
        InitializeComponent();
        this.Controls.Add(radGridView = new RadGridView());
        radGridView.Dock = DockStyle.Fill;
        radGridView.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
        radGridView.DataSource = new TestsCollection(10);
        radGridView.EnableFiltering = true;
        radGridView.ContextMenuOpening += new ContextMenuOpeningEventHandler(radGridView_ContextMenuOpening);
    }
 
    void radGridView_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
    {
        var dataCell = e.ContextMenuProvider as GridDataCellElement;
        if (dataCell == null)
        {
            e.Cancel = true;
            return;
        }
 
        e.ContextMenu.Items.Clear();
        var copyItem = new RadMenuItem("Copy", dataCell.Value);
        copyItem.Click += new EventHandler(copyItem_Click);
        e.ContextMenu.Items.Add(copyItem);
 
        var pasteItem = new RadMenuItem("Paste");
        pasteItem.Click += new EventHandler(pasteItem_Click);
        e.ContextMenu.Items.Add(pasteItem);
    }
 
    void pasteItem_Click(object sender, EventArgs e)
    {
        if (radGridView.CurrentCell == null)
        {
            return;
        }
 
        radGridView.CurrentCell.Value = Clipboard.GetText();
    }
 
    void copyItem_Click(object sender, EventArgs e)
    {
        var menuItem = sender as RadMenuItem;
        if (menuItem == null)
        {
            return;
        }
 
        var cellValue = menuItem.Tag;
        Clipboard.SetText(cellValue.ToString());
    }
}
 
public class Test
{
    public int Id
    {
        get;
        set;
    }
 
    public string Name
    {
        get;
        set;
    }
}
 
public class TestsCollection : BindingList<Test>
{
    public TestsCollection(int noItems)
    {
        for (int i = 0; i < noItems; i++)
        {
            this.Add(new Test
            {
                Id = i,
                Name = "Name" + i
            });
        }
    }
}

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Telerik WinForms MVP
Tags
GridView
Asked by
salini
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Fernando
Top achievements
Rank 1
salini
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
Share this question
or