Click here to Skip to main content
15,944,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm quite lost with something which is supposed to be simple.
I have Master/Detail/Detail relationship between 3 tables, master is set of controls and working smoothly with first detail this detail is the master of the second detail.

Master --> Detail(Master) D1 ---> Detail D2

D1 is binded to datagridview and D2 also binded to datagridview,
The usual scenario When you select a row from the master DataGridView,
the detail DataGridView gets populated with the columns related to the selected row,

and this working so fine but if i have more than one row in mater data grid and try to change selection between them the design of the second gridview break down and all rows disappear and when try to click save i got this exception "index must be non negative".

you can find image for what i mean here

I am using .net 4.6 and nettires with codesmith generator .


Any suggestions !!!

What I have tried:

Function For binding

   public void SetActiveBindingByActiveControl(Control ctrl)
        {
            BindingSource bsSource = null;
            if (ctrl.GetType() == typeof(AdvancedDataGridView))
                bsSource = (BindingSource)((AdvancedDataGridView)ctrl).DataSource;

            else if (ctrl.GetType() == typeof(SmartDataGidView))
                bsSource = (BindingSource)((SmartDataGidView)ctrl).DataSource;
            else
            {
                PropertyInfo pi = ctrl.GetType().GetProperty("DataBindings");
                if (pi != null)
                {
                    ControlBindingsCollection coll = (ControlBindingsCollection)pi.GetValue(ctrl, null);
                    if (coll.Count > 0)
                        bsSource = (BindingSource)coll[0].DataSource;
                }
            }

            SetActiveBindingByBindingSource(bsSource);
        }
Posted

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