Reputation: 9876
What I need to do is to capture the data before being loaded in the dgv and change one of the properties. What I have now is a generic method which I'm using to create the DataSource
for my dgv:
dgv.DataSource = new SortableBindingList<T>(result.ResultEntities);
And what I want to do is to get this data, manipulate it the way I need and then return the changed data for loading in the dgv
.
I tried to accomplish this by simply doing this:
SortableBindingList<MyType> someVar = (SortableBindingList<MyType>)dgvMydgv.DataSource;
well, it seems it's not the way to do this.
Upvotes: 0
Views: 353
Reputation: 216
If you bind a local variable like your sortableBindingList to an datagridview its not accessable after the datagrid databound successfully. datasource will be NULL after the "DataBound()"-Event fired.
FYI:
If you bind a SqlDataSource
to your datagridview you are able to Export the sortablebindinglist after you bound the datasource.
you have to read out every column in every row and save it in a new defined sortablebindinglist and then rebind the datasource to the gridview:
foreach (GridViewRow gvrMyRow in gvFields.Rows)
{
foreach (TableCell tcMyCell in gvrMyRow.Cells)
{
string sMyValue = tcMyCell.Text;
}
}
Keep in mind:
keeping the refference to the original filled list is the normal way to go and you should go to achive this way. its way easier to find entries, manipulate entries and so on.
Upvotes: 1