Link to home
Start Free TrialLog in
Avatar of TrinitySolutions
TrinitySolutions

asked on

Master and Detail Grids

Guess I'm just not searching right, because this doesn't seem to be a big thing.

I'm using VWD 2008, so would prefer instructions on using it instead of code (which I'm still fairly weak on).

I want a grid that will allow me to show limited information about a row.  When clicking on an 'edit' button, I want the remaining data about that same row to show up and be editable.

I've used a Formview, but can't seem to make it link back to my initial data list.  I'm sure it should be receiving a passed variable somewhere.  Analytically, I get it, just can't get it in the pc!

What form/grid would be best to use initially - how should it pass the paramater - to what grid should it be passed to be able to edit it1?
Avatar of Arno Koster
Arno Koster
Flag of Netherlands image

You can make a custom form with the layout you want and all the fields you would want to edit.
When the user clicks on the edit button, the actual selected row is used to populate a datatable. This datatable is then used to populate the form with data.
When the user accepts the edited data, the updated recordset can then be used to update the data in the original table.

This way you can easily verify the correct working of the different steps of the progress (filling the recordset, using recordset data to populate the form, editing data in the recordset, updating original data from the recordset)

Avatar of TrinitySolutions
TrinitySolutions

ASKER


Thanks.  Sounds like a little more work than I had hoped for.  A little more  research shows I should be able to have a datagrid, and somehow link it to another page.  This is more of a Master/Detail item - for instance, you see the name and address listed in the first table, clicking on the edit button will show you all of the additional fields of that record on a separate page ready for editing in another grid.

I'm sure there's got to be a fairly straightforward way to have (in Visual Studio) it 'pass' the row to open in the second page for editing without fighting the coding.
well,

you would normally find out the data row you have selected in the master grid (e.g. the row ID).
Then you would use this to populate the detail grid.

You could do this by populating a datatable, which indeed is more work but will be more easily debugged when you encounter problems.
You also could use the following code :



        private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            int rowID = (int)dataGridView1.Rows[e.RowIndex].Cells[0].Value;
            db6DataSet1.Table_AllDataTable data = new db6DataSet1.Table_AllDataTable();
            db6DataSet1TableAdapters.Table_AllTableAdapter TableAdapter = new WindowsFormsApplication8.db6DataSet1TableAdapters.Table_AllTableAdapter();
            TableAdapter.Fill(data);
 
            var selection = data.Where(row => row.id == rowID);
            dataGridView2.DataSource = selection.ToList();
            dataGridView2.Refresh();
           
        }

Open in new window

Akoster - While I appreciate your work, and am jealous of your knowledge, I really want to be able to have it built using the Visual Studio 'easy button' with Gridview and be able to Drill down to the details on the details form.  I have several of these scenarios to set up, and with my limited coding skills I need to do it the easy way for now.
If you want to use only the easy button options, you will be able to get a limited set of data into a gridview.

At the same time you can textboxes which too are linked to the same set of data. When the user clicks on a row in the gridview, the textboxes are automatically filled with the appropriate information.

All this can be done without writing a single line of code.

When however you want things to show up / become editable / spread functionality into different forms etc you will have to use code.
ASKER CERTIFIED SOLUTION
Avatar of kellysmith120
kellysmith120

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial