Click here to Skip to main content
15,902,939 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

On my for i have 4 DataGridView,

In click on the first dgv1 the other tree are populated with data, works fine only when are record to display.

When i change selection for dgv1, but the rest 3 dgv has info on my fist selection and the second selection has no record for the second dgv2, the dgv3 and dgv4 has record from the first selection.

What event to use for update dgv2, dgv3, dgv4,

dgv2 is updated based on dgv1 - this is OK
dgv3, dgv 4 based on dgv2 - this NOT

private void dgv2_SelectionChanged(object sender, EventArgs e)
            if (dvContracte.SelectedRows.Count > 0)
                int nrContractCautat = Convert.ToInt32(dvContracte.SelectedRows[0].Cells[0].Value.ToString());
                if (nrContractCautat != 0)
                    ProduseContract[] produseContract = InterogariDB.produseContract(nrContractCautat);
                    dataConProduse.DataSource = produseContract;
                    this.dataConIstoric.DataSource = InterogariDB.IncarcaIstoricContracte(nrContractCautat);
Updated 25-Jan-15 19:53pm
Sinisa Hajnal 26-Jan-15 2:18am    
In what way this is not OK? You get an error? The event doesn't trigger? Move the code in the event into separate method and call the method after you bind dgv2 - and call it in SelectionChanged like here.
Alternatively, try setting explicitely the selection on dgv2 once it is bound from dgv1 event.
aciobanita constantin 26-Jan-15 3:19am    
So, on click dgv1 - the dgv2 may have or not record, if dgv2 has record, dgv3 and dgv4 has records, if dgv2 has no record, dgv3 and dgv4 not have record (this is OK), but a succes show the record on dgv2, when i change row from the dgv1 and dgv2 has no records (this can occur and is OK), the dgv3 and dgv4 has the same record from the firs select dgv1, in this situation dgv3 and dgv4 must not have records - how to empy (has datasource), i try with dgv1.Update().
Sinisa Hajnal 26-Jan-15 3:24am    
You'll have to check dgv2 row count and explicitely delete datasources from dgv3 and 4. You could try putting the clearing in else clause in dgv2_SelectionChanged, but I'm not sure emptying dgv2 will trigger the event.
V. 26-Jan-15 7:11am    
Do you create a new DataGridView through code? If so, make sure to attach the event handler again with += ....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900