Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating Grid without rebinding - Winforms? 1

Status
Not open for further replies.

jtrembla

ISP
Jul 6, 2006
104
US
The scenario,

I am populating a grid using a stored procedure that pivots 2 normalized tables. When a user changes a cell value I send that change back to the database where a transaction is run to recalculate certain values in the normalized tables. I then rebind the updated stored procedure to the grid.

Problem
if the grid is being grouped by a column and it is expanded the grid resets and redraws itself thus collapsing itself. Obviously this is bad for the User.

My question is, is there a way I can update the grid without resetting/redrawing it. Would using a middle datasource work? I guess I could also save row state on the client side.

Thanks
 
i work with asp.net, not sure the exact differences of win/web. I would save the state of the grid to a local variable. re-bind the grid, and then restore the state.

a "middle datasource" wouldn't fix the state issue. the grid doesn't care where the data came from only that it's enumerable data.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Do you have any code that shows how I can completely save the state of the grid? I needs to know the columns that are grouped, and also the state of each row.
 
sorry, no code, i haven't worked in the winforms enviornment. if you need the state of each row and the groups then i would create a list<T> of object to group by and add them
in order of grouping first to last. do the same for row state using an idictionary<rowidentifier, rowstate>

after bind the grid add each of the groups back to the grid. then loop through the rows. if the row matches the dictionarty key, set the row state.

pseudo code would look like this
Code:
private IList<[ObjectToGroupBy]> listOfGroupings;
private IDictionary<[RowDataItem], RowState> listOfRowStates;

public void Just_Before_Grid_Binding(...)
{
   foreach (Grouping group in Grid.Groups)
   {
       listOfGroupings.Add(group);
   }
   foreach (GridRow row in Grid.Rows)
   {
       listOfRowStates[row.DataItem] = row.RowState;
   }
}

public void Just_After_Grid_Bound(...)
{
   foreach (Grouping group in listOfGroupings)
   {
       Grid.Groups.Add(group);
   }
   foreach ([DataItem] item in listOfRowStates.Keys)
   {
       foreach (GridRow row in Grid.Rows)
       {
           if(item == row.DataItem) row.RowState = listOfRowStates[item];
       }
   }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top