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

DropDown or ComboBox for filtering a gridview

2 Answers 574 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tommy
Top achievements
Rank 1
Tommy asked on 05 Jul 2010, 04:56 PM
I have been looking all weekend for this solution but cant seem to figure it out.  I have a sql database, very small and simple.  It is basically is a support database for taking service requests.  (just a training for myself)  I have a database view that i'm using to bring the information into my winform project.

I'm trying to figure out the best way to filter a gridview using the dropdown.

1.  Is it possible to populate a RadDropDownButton with the Technician Name items from a sql database and then filter the records in a gridview?
2. Is it better to use a combobox although the dropdown seems to look cooler?

So I have a radform, drop a raddropdown and a gridview on the form... I can get the gridview to display records, I can get a combobox to show the technicians but I can only get the dropdown to display the first technician.

I have not been able to get any of the dropdowns or combobox's to filter the gridview.. anybody have any simple solutions that I may be missing? 

I have tried several different ways, one such as this:

Public Class RadForm1  
 
     
 
    Private Sub RadForm1_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load  
        'TODO: This line of code loads data into the 'WODataset.WorkOrderMain' table. You can move, or remove it, as needed.  
        Me.WorkOrderMainTableAdapter.Fill(Me.WODataset.WorkOrderMain)  
 
        RadDropDownButton1.Items.Add(WODataset.WorkOrderMain.techFullNameColumn)  
        RadComboBox1.Items.Add(WODataset.WorkOrderMain.techFullNameColumn)  
 
    End Sub 
End Class 
Both of these do not work for populating the fields...

Please excuse my noviceness... :)

 

2 Answers, 1 is accepted

Sort by
0
Tommy
Top achievements
Rank 1
answered on 06 Jul 2010, 02:37 PM
Maybe that was to convoluted:

If i start with a radform, drop a combobox on it, set it to a column of data in my sql datasource, and then drop a gridview on the form, how do I use the combobox to display onlly the records associated with what was selected?

Public Class RadForm1  
 
    Private Sub RadForm1_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load  
        'TODO: This line of code loads data into the 'MyCompanyDataSet.Customers' table. You can move, or remove it, as needed.  
        Me.CustomersTableAdapter.Fill(Me.MyCompanyDataSet.Customers)  
 
    End Sub 
 
    Private Sub RadComboBox1_SelectedIndexChanged(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles RadComboBox1.SelectedIndexChanged  
        'I'm assuming something should go here to link the combobox selectedindexchanged to the radgridview  
 
 
    End Sub 
End Class 
0
Jack
Telerik team
answered on 06 Jul 2010, 04:21 PM
Hi Tommy,

Thank you for contacting us. Regarding your questions:

1. Yes, this is possible. However, our drop-down button doesn't support data binding. You have to add all items manually. Here is a sample:

RadDropDownButton button = new RadDropDownButton();
DataTable table = new DataTable();
 
//...
 
for (int i = 0; i < table.Rows.Count; i++)
{
    button.Items.Add(new RadMenuItem((string)table.Rows[i]["Name"], table.Rows[i]["ID"]));
}

2. It depends on your preferences and choice, however binding combobox is simpler:

RadComboBox combobox = new RadComboBox();
DataTable table = new DataTable();
 
//...
 
combobox.DataSource = table;

In order to filter RadGridView you have to add a FilterExpression. Consider the following sample:

FilterExpression filter = new FilterExpression();
filter.Predicates.Add(FilterExpression.BinaryOperation.AND, GridKnownFunction.GreaterThan, "@FilterEditor1");
filter.Parameters.Add("@FilterEditor1", "15");
this.radGridView1.Columns["Value"].Filter = filter;

You can find further details in our online help. If you have any other questions, don't hesitate to write us.

Kind regards,
Jack
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Tommy
Top achievements
Rank 1
Answers by
Tommy
Top achievements
Rank 1
Jack
Telerik team
Share this question
or