vb.net 2005 DataBinding to controls
-
Ok, not sure exactly how to word this so here goes. I have a winform in my project that has the following: Controls 1. DropDownList1 - Customer Name 2. TextBox1 - Customer ID 3. DropDownList2 - Site Name DataBase Tables 1. tblCust - Fields(CustName, CustID, Status) 2. tblCustSiteAssoc - Fields(CustId, CustSiteID) 3. tblCustSite - Fields(CustSiteID, CustSiteName, ...) What I am trying to do is this: 1. When the form open have customers names bound to the DropDownList1 control with nothing selected 2. Once I select something in the DropDownList1 control (SelectedIndexChanged) have it update the other two controls with the selected customers' data. I assume I make a DataSet that queries all three tables and I understand how to bind the CustName to the first DropDownList box. What I don't understand is how to use the selected information to get the relevant information for the other two controls. Thanks in advance, Taen Karth
-
Ok, not sure exactly how to word this so here goes. I have a winform in my project that has the following: Controls 1. DropDownList1 - Customer Name 2. TextBox1 - Customer ID 3. DropDownList2 - Site Name DataBase Tables 1. tblCust - Fields(CustName, CustID, Status) 2. tblCustSiteAssoc - Fields(CustId, CustSiteID) 3. tblCustSite - Fields(CustSiteID, CustSiteName, ...) What I am trying to do is this: 1. When the form open have customers names bound to the DropDownList1 control with nothing selected 2. Once I select something in the DropDownList1 control (SelectedIndexChanged) have it update the other two controls with the selected customers' data. I assume I make a DataSet that queries all three tables and I understand how to bind the CustName to the first DropDownList box. What I don't understand is how to use the selected information to get the relevant information for the other two controls. Thanks in advance, Taen Karth
When you create your Dataset define a relation between all three tables. It may be better to do this back at the underlying database. Then bind all three controls to the DataSet as you normally would. Now when you select something from DropDownList1 the other two controls will display the proper related data. I hope this helps.
-
When you create your Dataset define a relation between all three tables. It may be better to do this back at the underlying database. Then bind all three controls to the DataSet as you normally would. Now when you select something from DropDownList1 the other two controls will display the proper related data. I hope this helps.
Ok I think I need to break this down a little bit more for the relation: Table1 CustID - PriKey - linked to Table2(CustID) CustName Status Table2 CustID CustSiteID Table3 CustSiteID - PriKey - linked to Table2(CustSiteID) CustSiteName Addr1 Addr2 City State etc... I have relationships setup like above. I created a new DataSet Item from Add New Item in IDE. Then it asks me to select Tables which I select the three above. It then adds these three tables to the designer with relationships and TableAdapters configured and all. I then go to DropDownList1 and set the DataSource to the DataSet. It creates a binding source and then I set DisplayMember to CustName and it creates a new TableAdapter. Now I want to select a customer name in DropDownList1 and have it filter DropDownList2 so that only SiteName shows that has a relationship between CustID and CustSiteID. I can only get DropDownList2 to list all SiteName. I can't figure out how to filter it. Thanks, Taen Karth
-
Ok I think I need to break this down a little bit more for the relation: Table1 CustID - PriKey - linked to Table2(CustID) CustName Status Table2 CustID CustSiteID Table3 CustSiteID - PriKey - linked to Table2(CustSiteID) CustSiteName Addr1 Addr2 City State etc... I have relationships setup like above. I created a new DataSet Item from Add New Item in IDE. Then it asks me to select Tables which I select the three above. It then adds these three tables to the designer with relationships and TableAdapters configured and all. I then go to DropDownList1 and set the DataSource to the DataSet. It creates a binding source and then I set DisplayMember to CustName and it creates a new TableAdapter. Now I want to select a customer name in DropDownList1 and have it filter DropDownList2 so that only SiteName shows that has a relationship between CustID and CustSiteID. I can only get DropDownList2 to list all SiteName. I can't figure out how to filter it. Thanks, Taen Karth
To filter use a DataView. You could say something like this: DropDownList2.DataSource = DataSet.Table3.DefaultView DropDownList2.DisplayMember = "CustSiteName" But, since you have the tables related to each other I don't think filtering is neccessary. Instead set it up like this: DropDownList2.DataSource = DataSet.Table3 DropDownList2.DisplayMember = "CustSiteName" Since Table3 is in a relation it will show the proper records in DropDownList2 Also, I think you could elliminate Table2 and have CustID in Table3.