Click here to Skip to main content
15,902,275 members
Home / Discussions / C#
   

C#

 
GeneralRe: datagridview filtering....where to start? Pin
Stanciu Vlad20-May-10 10:22
Stanciu Vlad20-May-10 10:22 
GeneralRe: datagridview filtering....where to start? [modified] Pin
mprice21424-May-10 8:24
mprice21424-May-10 8:24 
GeneralRe: datagridview filtering....where to start? Pin
Stanciu Vlad25-May-10 21:12
Stanciu Vlad25-May-10 21:12 
GeneralRe: datagridview filtering....where to start? Pin
mprice21426-May-10 7:48
mprice21426-May-10 7:48 
GeneralRe: datagridview filtering....where to start? Pin
Stanciu Vlad26-May-10 10:05
Stanciu Vlad26-May-10 10:05 
GeneralRe: datagridview filtering....where to start? Pin
mprice21426-May-10 17:43
mprice21426-May-10 17:43 
GeneralRe: datagridview filtering....where to start? Pin
Stanciu Vlad26-May-10 20:43
Stanciu Vlad26-May-10 20:43 
GeneralRe: datagridview filtering....where to start? <Solved> Pin
mprice21426-May-10 18:52
mprice21426-May-10 18:52 
from:

http://social.msdn.microsoft.com/forums/en-US/winformsdatacontrols/thread/6f6c2632-afd7-4fe9-8bf3-c2c8c08d1a31/[^]

public partial class Form1 : Form
    {
        DataTable tblPrimary, tblSecondary;
        BindingSource primaryBS, filteredSecondaryBS, unfilteredSecondaryBS;
        
        public Form1()
        {

            tblPrimary = new DataTable("Primary");
            tblPrimary.Columns.Add("ID", typeof(int));
            tblPrimary.Columns.Add("Name", typeof(string));

            tblSecondary = new DataTable("Secondary");
            tblSecondary.Columns.Add("ID", typeof(int));
            tblSecondary.Columns.Add("subID", typeof(int));
            tblSecondary.Columns.Add("Name", typeof(string));

            tblPrimary.Rows.Add(new object[] { 0, "Force" });
            tblPrimary.Rows.Add(new object[] { 1, "Torque" });
            tblPrimary.Rows.Add(new object[] { 2, "Pressure" });

            tblSecondary.Rows.Add(new object[] { 0, 0, "lb" });
            tblSecondary.Rows.Add(new object[] { 1, 0, "N" });
            tblSecondary.Rows.Add(new object[] { 2, 0, "oz" });
            tblSecondary.Rows.Add(new object[] { 3, 1, "in-lb" });
            tblSecondary.Rows.Add(new object[] { 4, 1, "ft-lb" });
            tblSecondary.Rows.Add(new object[] { 5, 1, "N-m" });
            tblSecondary.Rows.Add(new object[] { 6, 2, "PSI" });
            tblSecondary.Rows.Add(new object[] { 7, 2, "Pa" });
            tblSecondary.Rows.Add(new object[] { 8, 2, "bar" });
            
            InitializeComponent();

            primaryBS = new BindingSource();
            primaryBS.DataSource = tblPrimary;
            primaryComboBoxColumn.DataSource = primaryBS;
            primaryComboBoxColumn.DisplayMember = "Name";
            primaryComboBoxColumn.ValueMember = "ID";

            // the ComboBox column is bound to the unfiltered DataView
            unfilteredSecondaryBS = new BindingSource();
            DataView undv = new DataView(tblSecondary);
            unfilteredSecondaryBS.DataSource = undv;
            secondaryComboBoxColumn.DataSource = unfilteredSecondaryBS;
            secondaryComboBoxColumn.DisplayMember = "Name";
            secondaryComboBoxColumn.ValueMember = "ID";

            // this binding source is where I perform my filtered view
            filteredSecondaryBS = new BindingSource();
            DataView dv = new DataView(tblSecondary);
            filteredSecondaryBS.DataSource = dv;
        }
                

       
        private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
                if (e.ColumnIndex == secondaryComboBoxColumn.Index)
                {
                    DataGridViewComboBoxCell dgcb = (DataGridViewComboBoxCell)dataGridView1[e.ColumnIndex, e.RowIndex];
                    dgcb.DataSource = filteredSecondaryBS;

                    this.filteredSecondaryBS.Filter = "subid = " +
                        this.dataGridView1[e.ColumnIndex - 1, e.RowIndex].Value.ToString();
                }
            
         }

        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
           
                if (e.ColumnIndex == this.secondaryComboBoxColumn.Index)
                {
                    DataGridViewComboBoxCell dgcb = (DataGridViewComboBoxCell)dataGridView1[e.ColumnIndex, e.RowIndex];
                    dgcb.DataSource = unfilteredSecondaryBS;

                    this.filteredSecondaryBS.RemoveFilter();
                }
        
        }

GeneralRe: datagridview filtering....where to start? Pin
Stanciu Vlad26-May-10 20:54
Stanciu Vlad26-May-10 20:54 
GeneralRe: datagridview filtering....where to start? Pin
mprice21427-May-10 3:13
mprice21427-May-10 3:13 
GeneralRe: datagridview filtering....where to start? Pin
Stanciu Vlad27-May-10 6:52
Stanciu Vlad27-May-10 6:52 
QuestionXML Serialization of derived classes Pin
Roland Bär7-May-10 12:35
Roland Bär7-May-10 12:35 
AnswerRe: XML Serialization of derived classes Pin
Peace ON7-May-10 21:40
Peace ON7-May-10 21:40 
AnswerRe: XML Serialization of derived classes Pin
Stanciu Vlad7-May-10 23:20
Stanciu Vlad7-May-10 23:20 
Questionhow can i make a distributed system through C# ? Pin
Med7at7-May-10 11:30
Med7at7-May-10 11:30 
AnswerRe: how can i make a distributed system through C# ? Pin
Garth J Lancaster7-May-10 13:43
professionalGarth J Lancaster7-May-10 13:43 
AnswerRe: how can i make a distributed system through C# ? Pin
Member 41702067-May-10 15:04
Member 41702067-May-10 15:04 
GeneralRe: how can i make a distributed system through C# ? Pin
Med7at7-May-10 15:47
Med7at7-May-10 15:47 
AnswerRe: how can i make a distributed system through C# ? Pin
Peace ON7-May-10 19:44
Peace ON7-May-10 19:44 
Questionreturn number of records selected Pin
Abdul-Rhman Alsri7-May-10 11:21
Abdul-Rhman Alsri7-May-10 11:21 
AnswerRe: return number of records selected Pin
Dr.Walt Fair, PE7-May-10 12:27
professionalDr.Walt Fair, PE7-May-10 12:27 
AnswerRe: return number of records selected Pin
Member 41702067-May-10 15:07
Member 41702067-May-10 15:07 
AnswerRe: return number of records selected Pin
Peace ON7-May-10 19:53
Peace ON7-May-10 19:53 
AnswerRe: return number of records selected Pin
Saiyed Alam7-May-10 20:42
Saiyed Alam7-May-10 20:42 
AnswerRe: return number of records selected Pin
Abhinav S7-May-10 21:05
Abhinav S7-May-10 21:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.