none
DataGridView not flitering detail record and ignoring foreign key relationship RRS feed

  • Question

  • <p>I have requirment in which i am showing Master- Detail information into DataGridView.</p><p> </p><p>I have add the foriegn key relationship to the Dataset. But Detail Grid is not flitering it self based on the selection of master. I dont know what I am missing here!</p><p> </p><p>Just to verify if the relationship exist , I have checked them using DataGrid. I shows up there.</p>
    
    namespace WindowsFormsApplication1 {  public partial class Form1 : Form  {   
     public Form1()  
      {     InitializeComponent();    } 
    
       DataSet CreateTableAndFill()  
     {   
      DataSet ds = new DataSet();  
       DataTable Header = ds.Tables.Add("Header"); 
        DataTable Line = ds.Tables.Add("Line");  
       DataColumn dataColumn = Header.Columns.Add("ID", typeof(int));    
     dataColumn.AutoIncrement = true;     dataColumn.AutoIncrementSeed = 1; 
        Header.Columns.Add("Name", typeof(string));  
       Line.Columns.Add("ID", typeof(int));
         Line.Columns.Add("Phone", typeof(string));     DataRelation dataRelation = new DataRelation("ID_FK", Header.Columns["ID"], Line.Columns["ID"]); 
        ds.Relations.Add(dataRelation);  
       Header.Rows.Add(null, "Huzaiafa");  
       Header.Rows.Add(null, "Arthur");   
      Line.Rows.Add(1, "4253068516");  
       Line.Rows.Add(1, "4252746864");   
      Line.Rows.Add(2, "5654034");   
      Line.Rows.Add(2, "12563");  
       return ds;   } 
      private void button1_Click(object sender, EventArgs e)   {    
     DataSet ds = CreateTableAndFill();    
    dataGridView1.DataSource = ds; 
       dataGridView2.DataSource = ds;    dataGridView1.DataMember = "Header";    dataGridView2.DataMember = "Line";   
    } 
    }
     } 
    

    http://stackoverflow.com/questions/5824101/datagridview-not-flitering-detail-record-and-ignoring-foreign-key-relationship

     


    Huzaifa
    Thursday, April 28, 2011 7:56 PM

Answers

  • Hi Huzaifa,

    Welcome to the MSDN fourm.

    I just browser the stackoverflow, Did you have validate the suggestion?

    Here is my test sample:

                DataSet ds = CreateTableAndFill();
                dataGridView1.DataSource = ds.Tables["Header"];
                dataGridView2.DataSource = ds;
                dataGridView2.DataMember = "Line";
                dataGridView1.DataMember = "ID_FK";

    I hope that woud be help. Best Regards.


    If it's helpful for you, Please vote or mark. Thank you!

    David Peng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, May 2, 2011 3:34 AM
    Moderator

All replies

  • I just read the thread over on Stackoverflow and it looks like you got a valid suggestion for solving your problem. Do you have it working now?


    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    Saturday, April 30, 2011 11:29 PM
  • Hi Huzaifa,

    Welcome to the MSDN fourm.

    I just browser the stackoverflow, Did you have validate the suggestion?

    Here is my test sample:

                DataSet ds = CreateTableAndFill();
                dataGridView1.DataSource = ds.Tables["Header"];
                dataGridView2.DataSource = ds;
                dataGridView2.DataMember = "Line";
                dataGridView1.DataMember = "ID_FK";

    I hope that woud be help. Best Regards.


    If it's helpful for you, Please vote or mark. Thank you!

    David Peng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, May 2, 2011 3:34 AM
    Moderator
  • Hello Huzaifa

    Thanks for your post.

    If you have any time, could you please tell me if their suggestions make sence? If they do, please mark it as answer. Or please feel free to tell me if you have any questions.

    Have a nice day,


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, May 5, 2011 3:29 AM
    Moderator