C# - Three Combobox - Databinding - DefaultView Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • einsson
    New Member
    • Dec 2007
    • 3

    #1

    C# - Three Combobox - Databinding - DefaultView Problem

    I face a problem, please help.
    Error I hit when there are three combobox.
    Please refer the code with italic characters.

    this.comboBox1. DataSource = this.dataSet11. Tables["PANEL"];
    this.comboBox2. DataSource = this.dataSet11. Tables["PANEL"].DefaultView;
    this.comboBox3. DataSource = dataSet11.Table s["PANEL"];[/


    The combobox1 value is as same as combobox3 value.
    The combobox2 value is different because Table[""].DefaultView is added.
    where combobox1,2,3 values are different at all.




    BindingManagerB ase bindManager1;
    BindingManagerB ase bindManager2;
    BindingManagerB ase bindManager3;
    BindingManagerB ase bindManager4;


    public Form1()
    {
    InitializeCompo nent();
    }


    private void Form1_Load(obje ct sender, EventArgs e)
    {
    cn1 = new OracleConnectio n(strConn);

    using (cn1)
    {
    cn1.Open();

    //da1 = new OracleDataAdapt er("SELECT CLIENTGRPNO, DESCRIPTION, OTHERDESC, PANELCODE, INCLUDEBANDED, BANDEDFLAG, OFFERITEM, OUTPUTDIR, CAUSALPANELCODE , AUDITPANELCODE, MBDTAG_ATTRNO FROM RRS.CLIENT_GROU P_MASTER ORDER BY CLIENTGRPNO", cn1);
    da1 = new OracleDataAdapt er("SELECT CLIENTGRPNO, DESCRIPTION, OTHERDESC, OUTPUTDIR, PANELCODE, CAUSALPANELCODE , AUDITPANELCODE FROM RRS.CLIENT_GROU P_MASTER ORDER BY CLIENTGRPNO", cn1);
    da1.Fill(this.d ataSet11, "CLIENT_GROUP_M ASTER");

    da2 = new OracleDataAdapt er("SELECT CLIENTGRPNO, CLIENTCODE FROM RRS.CLIENT_GROU P_DETAIL ORDER BY CLIENTGRPNO", cn1);
    da2.Fill(this.d ataSet11, "CLIENT_GROUP_D ETAIL");

    da3 = new OracleDataAdapt er("SELECT CLIENTCODE, CLIENTNAME FROM RRS.CLIENT_MAST ER ORDER BY CLIENTCODE", cn1);
    da3.Fill(this.d ataSet11, "CLIENT_MASTER" );

    da4 = new OracleDataAdapt er("SELECT PANELCODE, DESCRIPTION FROM RRS.PANEL ORDER BY PANELCODE", cn1);
    da4.Fill(this.d ataSet11, "PANEL");


    }

    this.comboBox1. DataBindings.Ad d("SelectedValu e", ds, "PANEL.DESCRIPT ION");
    this.comboBox2. DataBindings.Ad d("SelectedValu e", ds, "PANEL.DESCRIPT ION");
    this.comboBox3. DataBindings.Ad d("SelectedValu e", ds, "PANEL.DESCRIPT ION");



    this.comboBox1. DataSource = null;
    this.comboBox1. DisplayMember = "DESCRIPTIO N";
    this.comboBox1. ValueMember = "PANELCODE" ;
    this.comboBox1. DataSource = this.dataSet11. Tables["PANEL"];


    this.comboBox2. DataSource = null;
    this.comboBox2. DisplayMember = "DESCRIPTIO N";
    this.comboBox2. ValueMember = "PANELCODE" ;
    this.comboBox2. DataSource = this.dataSet11. Tables["PANEL"].DefaultView;

    this.comboBox3. DataSource = null;
    this.comboBox3. DisplayMember = "DESCRIPTIO N";
    this.comboBox3. ValueMember = "PANELCODE" ;
    this.comboBox3. DataSource = dataSet11.Table s["PANEL"];


    this.bindManage r1 = this.BindingCon text[this.dataSet11, "CLIENT_GROUP_M ASTER"];
    this.bindManage r2 = this.BindingCon text[this.dataSet11, "CLIENT_GROUP_D ETAIL"];
    this.bindManage r3 = this.BindingCon text[this.dataSet11, "CLIENT_MAS TER"];
    this.bindManage r4 = this.BindingCon text[this.dataSet11, "PANEL"];

    Binding b1 = new Binding("Text", dataSet11, "CLIENT_GROUP_M ASTER.CGMaster_ Panel.DESCRIPTI ON");
    this.comboBox1. DataBindings.Ad d(b1);
    Binding b2 = new Binding("Text", dataSet11, "CLIENT_GROUP_M ASTER.CGMaster_ CausalPanel.DES CRIPTION");
    this.comboBox2. DataBindings.Ad d(b2);
    Binding b3 = new Binding("Text", dataSet11, "CLIENT_GROUP_M ASTER.CGMaster_ AuditPanel.DESC RIPTION");
    this.comboBox3. DataBindings.Ad d(b3);
    }
  • einsson
    New Member
    • Dec 2007
    • 3

    #2
    Hi All,

    Regarding the problem I mentioned in post #1, I still need to explain the code I paste in #1.

    I use vs2005 wizard to generate four tables in one dataset --"dataSet11" :
    1. CLIENT_GROUP_MA STER
    2. CLIENT_GROUP_DE TAIL
    3. CLIENT_MASTER
    4. PANEL

    and its relation:
    Table 1.-> Table 2. = CGMaster_CGDeta il (PK = ClientGrpNo, FK = ClientGrpNo)
    Table 2.-> Table 3. = CGDetail_CMaste r (PK = ClientCode, FK = ClientCode)
    Table 1.-> Table 4. = CGMaster_Panel, CGMaster_Causal Panel, CGMaster_AuditP anel.
    (PK = panelcode, FK = panelcode)
    (PK = causalpanelcode , FK = panelcode)
    (PK = auditpanelcode, FK = panelcode)

    Besides the explanation, I still have 1 more question.
    What should I do if I want to implement master-detail feature into DataGridView:

    I prefer to add the code as shown below before "private void Form1_Load(obje ct sender, EventArgs e)" closed:

    WHEN I ADD THE CODE BELOW, it works, result as my expected:
    this.dataGridVi ew1.DataSource = this.dataSet11. Tables["CLIENT_GROUP_M ASTER"];
    this.dataGridVi ew1.DataMember = "CGMaster_CGDet ail";

    BUT, WHEN I ADD THE CODE BELOW, no joy:
    this.dataGridVi ew2.DataSource = this.dataSet11;
    this.dataGridVi ew2.DataMember = "CLIENT_GROUP_D ETAIL.CGDetail_ CMaster ";

    Thanks all.

    Regards,
    einsson

    Originally posted by einsson
    I face a problem, please help.
    Error I hit when there are three combobox.
    Please refer the code with italic characters.

    this.comboBox1. DataSource = this.dataSet11. Tables["PANEL"];
    this.comboBox2. DataSource = this.dataSet11. Tables["PANEL"].DefaultView;
    this.comboBox3. DataSource = dataSet11.Table s["PANEL"];[/


    The combobox1 value is as same as combobox3 value.
    The combobox2 value is different because Table[""].DefaultView is added.
    where combobox1,2,3 values are different at all.




    BindingManagerB ase bindManager1;
    BindingManagerB ase bindManager2;
    BindingManagerB ase bindManager3;
    BindingManagerB ase bindManager4;


    public Form1()
    {
    InitializeCompo nent();
    }


    private void Form1_Load(obje ct sender, EventArgs e)
    {
    cn1 = new OracleConnectio n(strConn);

    using (cn1)
    {
    cn1.Open();

    //da1 = new OracleDataAdapt er("SELECT CLIENTGRPNO, DESCRIPTION, OTHERDESC, PANELCODE, INCLUDEBANDED, BANDEDFLAG, OFFERITEM, OUTPUTDIR, CAUSALPANELCODE , AUDITPANELCODE, MBDTAG_ATTRNO FROM RRS.CLIENT_GROU P_MASTER ORDER BY CLIENTGRPNO", cn1);
    da1 = new OracleDataAdapt er("SELECT CLIENTGRPNO, DESCRIPTION, OTHERDESC, OUTPUTDIR, PANELCODE, CAUSALPANELCODE , AUDITPANELCODE FROM RRS.CLIENT_GROU P_MASTER ORDER BY CLIENTGRPNO", cn1);
    da1.Fill(this.d ataSet11, "CLIENT_GROUP_M ASTER");

    da2 = new OracleDataAdapt er("SELECT CLIENTGRPNO, CLIENTCODE FROM RRS.CLIENT_GROU P_DETAIL ORDER BY CLIENTGRPNO", cn1);
    da2.Fill(this.d ataSet11, "CLIENT_GROUP_D ETAIL");

    da3 = new OracleDataAdapt er("SELECT CLIENTCODE, CLIENTNAME FROM RRS.CLIENT_MAST ER ORDER BY CLIENTCODE", cn1);
    da3.Fill(this.d ataSet11, "CLIENT_MASTER" );

    da4 = new OracleDataAdapt er("SELECT PANELCODE, DESCRIPTION FROM RRS.PANEL ORDER BY PANELCODE", cn1);
    da4.Fill(this.d ataSet11, "PANEL");


    }

    this.comboBox1. DataBindings.Ad d("SelectedValu e", ds, "PANEL.DESCRIPT ION");
    this.comboBox2. DataBindings.Ad d("SelectedValu e", ds, "PANEL.DESCRIPT ION");
    this.comboBox3. DataBindings.Ad d("SelectedValu e", ds, "PANEL.DESCRIPT ION");



    this.comboBox1. DataSource = null;
    this.comboBox1. DisplayMember = "DESCRIPTIO N";
    this.comboBox1. ValueMember = "PANELCODE" ;
    this.comboBox1. DataSource = this.dataSet11. Tables["PANEL"];


    this.comboBox2. DataSource = null;
    this.comboBox2. DisplayMember = "DESCRIPTIO N";
    this.comboBox2. ValueMember = "PANELCODE" ;
    this.comboBox2. DataSource = this.dataSet11. Tables["PANEL"].DefaultView;

    this.comboBox3. DataSource = null;
    this.comboBox3. DisplayMember = "DESCRIPTIO N";
    this.comboBox3. ValueMember = "PANELCODE" ;
    this.comboBox3. DataSource = dataSet11.Table s["PANEL"];


    this.bindManage r1 = this.BindingCon text[this.dataSet11, "CLIENT_GROUP_M ASTER"];
    this.bindManage r2 = this.BindingCon text[this.dataSet11, "CLIENT_GROUP_D ETAIL"];
    this.bindManage r3 = this.BindingCon text[this.dataSet11, "CLIENT_MAS TER"];
    this.bindManage r4 = this.BindingCon text[this.dataSet11, "PANEL"];

    Binding b1 = new Binding("Text", dataSet11, "CLIENT_GROUP_M ASTER.CGMaster_ Panel.DESCRIPTI ON");
    this.comboBox1. DataBindings.Ad d(b1);
    Binding b2 = new Binding("Text", dataSet11, "CLIENT_GROUP_M ASTER.CGMaster_ CausalPanel.DES CRIPTION");
    this.comboBox2. DataBindings.Ad d(b2);
    Binding b3 = new Binding("Text", dataSet11, "CLIENT_GROUP_M ASTER.CGMaster_ AuditPanel.DESC RIPTION");
    this.comboBox3. DataBindings.Ad d(b3);
    }

    Comment

    • einsson
      New Member
      • Dec 2007
      • 3

      #3
      Since The dataset11.Table["Panel"] cannot support on more than two combobox objects, create another new Table --eg. dataset11.Table["Panel1"] can solve the problem .... althought this is not the best answer but alternative answer ....

      Comment

      Working...