Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
50
databind destroys expanded rows, but need to databind
posted

 So I need to databind again because of stored procedures running on the database, and I need to show those changes in the grid.

 Running databind again works, but you loose the expanded rows, selected rows etc.

 So surely theres a way to re-read the data from the dataset without databind?.

Thanks. 

Parents
No Data
Reply
  • 194
    posted

    I had this problem and found two workaround. One was to store the expanded state before databind and then restore it after. The other was to write my own "re-databind" function. Attached is the re-databind function. I'd have to do some digging in the history of the project for the expand store/restore code 'cause it's deleted now but I'll look it up if the "re-databind" doesn't work for you.

    The only issue is that it doesn't handle new rows right now. It should be fairly easy to modify to allow it to pickup new rows.

            protected static void RecursiveUpdateRows(DataSet updatedDataSet, RowsCollection rows, int level)
            {
                DataTable tableToReadFrom = updatedDataSet.Tables[level];
                foreach (UltraGridRow row in rows)
                {
                    UpdateUltraGridRowFromDataTable(tableToReadFrom, row);
                    if (row.HasChildRows == true)
                    {
                        RecursiveUpdateRows(updatedDataSet, row.Rows, level + 1);
                    }
                }
            }

            private static void UpdateUltraGridRowFromDataTable(DataTable tableToReadFrom, UltraGridRow rowToUpdate)
            {
                int rowIndex = (int)rowToUpdate.Cells[0].Value;

                DataRowView updatedRow = tableToReadFrom.DefaultView[rowIndex];

                foreach (UltraGridCell cell in rowToUpdate.Cells)
                {
                    string columnName = cell.Column.BaseColumnName;
                    object cellValue = cell.Value;
                    if (cellValue == null)
                    {
                        if (updatedRow[columnName] != null && updatedRow[columnName] != DBNull.Value)
                        {
                            cell.Value = updatedRow[columnName];
                        }
                    }
                    else if (cell.Value.Equals(updatedRow[columnName]) == false)
                    {
                        cell.Value = updatedRow[columnName];
                    }
                }
            }

     

    Edit: Fixed the formatting of the code. It also appeared that I was missing the function declaration of the first function.

Children