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.


    Private Sub FpSpread1_Change(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.ChangeEventArgs) Handles FpSpread1.Change


    For i As Integer = e.Row + 1 To e.View.Sheets(0).RowCount - 1


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


    Next


    End Sub


    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