Populate same value across column

Posted by: maneesh on 8 September 2017, 1:23 pm EST

  • Posted 8 September 2017, 1:23 pm EST

    I have a hierarchical view (depth = 2).

    In the child view, when somebody changes a value in a row, I want the same value to be reflected across all cells in the column of the child view.

    Any ideas of what approach I can take for accomplishing this?

    The grid is bound to a strongly typed dataset (2 tables, related), which is how I get the hierarchical view.  If I go through the strongly typed DataSet, and call

    ds.GetChanges(), that only gives me a DataTable containing changed rows.  Is there any way I can find out what columns of a changed row were changed?

  • Replied 8 September 2017, 1:23 pm EST

    Hello,


    I used code like the following to catch the Change event and populate the rest of the rows in the changed column in the changed child sheet with the changed value.

    <FONT size=2>

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Private</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Sub</FONT></FONT><FONT size=2> FpSpread1_Change(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>ByVal</FONT></FONT><FONT size=2> sender </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Object</FONT></FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>ByVal</FONT></FONT><FONT size=2> e </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> FarPoint.Win.Spread.ChangeEventArgs) </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Handles</FONT></FONT><FONT size=2> FpSpread1.Change


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>For</FONT></FONT><FONT size=2> i </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Integer</FONT></FONT><FONT size=2> = e.Row + 1 </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>To</FONT></FONT><FONT size=2> e.View.Sheets(0).RowCount - 1


    e.View.Sheets(0).SetValue(i, e.Column, e.View.Sheets(0).GetValue(e.Row, e.Column))


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Next

    </FONT></FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>End</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Sub</FONT></FONT>


    There is not a way to find the changed columns from the bound DataSource. You can only get the changed rows like you are.

  • Replied 8 September 2017, 1:23 pm EST

    The method works perfectly to change the values on the grid.

    However, the underlying row bound to the changed column is not market dirty, which is why I cannot see the changes to the bound DataTable (even if I click somewhere else in the grid)

    Any workaround?

  • Replied 8 September 2017, 1:23 pm EST

    I'm going to answer my own question.  This is a snippet of code I've used in , based on an earlier post:

    private void fpSpreadEditInc_Change(object sender, ChangeEventArgs e)

    {

                if (e.Row == 0)
                {
                    //If things are changed for the first row, I want the same value to be reflected to all columns in the expanded ChildView

                    for (int i = e.Row + 1; i < e.View.Sheets[0].RowCount; i++)
                    {
                        e.View.Sheets[0].SetValue(i, e.Column, e.View.Sheets[0].GetValue(e.Row, e.Column));

                        //Find out some values to identify the row in DataTable which needs to change

                        int iRgnNum = Convert.ToInt32(e.View.Sheets[0].GetValue(i, 0));
                        int modelID = Convert.ToInt32(e.View.Sheets[0].GetValue(i, 1));
                        string sFilterExpr = string.Format("ModelID = {0} AND RgnNum = {1}", modelID, iRgnNum);

                        DataRow[] rowsToChange = dataSetIncentives.DataTableIncentives.Select(sFilterExpr);

                        //Now call EndInit() on the found row (there will only be 1 in my case)

                        rowsToChange[0].EndEdit();
                    }
                }

    }

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels