|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Related tables for grids in vs 2005I'm quite new to VS 2005, and tries to connect several controls at my form. I thought this should be simple without writing code, but I can't get it to work. I have one dataset with two related tables. In my form I have two datagridviews. The first has datasource set to the dataset and datamember set to the first table. The second has the datasource set to the dataset and datamember set to the second table. I've tried more combinations, but really don't understand what to do and how it works. What I want: I click a row in the first datagridview, for instance with a primary key value set to 17. When I do this I only want to see those rows with foreign key value set to 17 in my second datagrid (and in the second table). I also want to be able to add rows to the second datagridview, so that the foreign key value is automatically set to 17. Shouldn't this be basic functionality, that not requires code??? Please help /Magnus Hi,
Show quote "Magnus Blomberg" <magnus.blomb***@skanska.se> wrote in message In NET2.0 it's more convenient if you put BindingSource's between them, so news:%23Ni6yn7FGHA.3892@TK2MSFTNGP12.phx.gbl... > Hello! > > I'm quite new to VS 2005, and tries to connect several controls at my > form. > I thought this should be simple without writing code, but I can't get it > to > work. > > I have one dataset with two related tables. > In my form I have two datagridviews. The first has datasource set to the > dataset and datamember set to the first table. > The second has the datasource set to the dataset and datamember set to the > second table. > I've tried more combinations, but really don't understand what to do and > how > it works. it should look like: MasterBindingSource DataSource=someDataSet DataMember="MasterTable" ChildBindingSource DataSource=someDataSet DataMember="MasterTable.RelationToChildTable" MasterDataGridView DataSoure = MasterBindingSource ChildDataGridView DataSource = ChildBindingSource > Make sure you have a Data Source ( Typed DataSet + TableAdapters ).> What I want: I click a row in the first datagridview, for instance with a > primary key value set to 17. > When I do this I only want to see those rows with foreign key value set to > 17 in my second datagrid (and in the second table). > I also want to be able to add rows to the second datagridview, so that the > foreign key value is automatically set to 17. > > Shouldn't this be basic functionality, that not requires code??? Menu->Data->Show Data Sources, create a new Data Source for the two tables if you haven't already. Then right click on the DataSet and choose open 'Edit DataSet with designer" and verify there is a relation between the two DataTable (indicated by a line), if there isn't then right-click on the empty space and choose add-relation. Now inside Data Sources window you should see your two tables. The tables have grids to the left of them while the fields have TextBox's on the left. So you can either drag the master table to the Form or some of the master table fields. Then you should also see inside Data Sources window that the master table has a field which also has a grid to the left (child table because of the relation). Now you can also drag that child table on the Form or any of it's field. That should setup most things, except you still need to add some code to the save button. See also: http://www.msdn.microsoft.com/vbasic/default.aspx?pull=/library/en-us/dnvs05/html/newdtastvs05.asp HTH, Greetings Show quote > > Please help > /Magnus > > [Snipped]
> In NET2.0 it's more convenient if you put BindingSource's between them, so Made a mistake with ChildBindingSource, should be:> it should look like: > > MasterBindingSource > DataSource=someDataSet > DataMember="MasterTable" > > ChildBindingSource > DataSource=someDataSet > DataMember="MasterTable.RelationToChildTable" ChildBindingSource DataSource=MasterBindingSource DataMember="RelationToChildTable" > Greetings> MasterDataGridView > DataSoure = MasterBindingSource > > ChildDataGridView > DataSource = ChildBindingSource > Show quote >> >> What I want: I click a row in the first datagridview, for instance with a >> primary key value set to 17. >> When I do this I only want to see those rows with foreign key value set >> to >> 17 in my second datagrid (and in the second table). >> I also want to be able to add rows to the second datagridview, so that >> the >> foreign key value is automatically set to 17. >> >> Shouldn't this be basic functionality, that not requires code??? > > Make sure you have a Data Source ( Typed DataSet + TableAdapters ). > > Menu->Data->Show Data Sources, create a new Data Source for the two tables > if you haven't already. Then right click on the DataSet and choose open > 'Edit DataSet with designer" and verify there is a relation between the > two DataTable (indicated by a line), if there isn't then right-click on > the empty space and choose add-relation. > > Now inside Data Sources window you should see your two tables. The tables > have grids to the left of them while the fields have TextBox's on the > left. So you can either drag the master table to the Form or some of the > master table fields. > Then you should also see inside Data Sources window that the master table > has a field which also has a grid to the left (child table because of the > relation). Now you can also drag that child table on the Form or any of > it's field. > > That should setup most things, except you still need to add some code to > the save button. > > See also: > http://www.msdn.microsoft.com/vbasic/default.aspx?pull=/library/en-us/dnvs05/html/newdtastvs05.asp > > > HTH, > Greetings > > >> >> Please help >> /Magnus >> >> > > |
|||||||||||||||||||||||