tags:

views:

192

answers:

1

Hello,

is it possible to display a DataRow from a DataTable which has the DataRowState.Deleted?

Scenario: The user can edit some kind of lookup-informations which are presented in the grid. Now he/she can delete, modify or insert multiple entries and finally store all his/her changes with one click to the database (assuming there is no primary-key-violation or some other problem).

Now i want to colorize the different rows according to their edit-status, but the deleted rows disappear immediatly.

Do you have any idea or another approach to solve this problem?

A: 

Edit: I realized that the Grid you are using is not DataGridView. For anyone who wants to do the same with DataGridView, they can do the following:

  1. Create a DataView:

    DataView myDataView = new DataView(myDataTable, String.Empty, // add a filter if you need one "SortByColumn", DataViewRowState.OriginalRows | DataViewRowState.Deleted);

    myDataGridView.DataSource = myDataView;

  2. Handle UserAddedRow, UserDeletedRow and CellValueChanged Events

    private void myDataGridView_UserAddedRow (object sender, DataGridViewRowEventArgs e) { e.Row.DefaultCellStyle.BackColor = ColorTranslator.FromHtml("#CCFF99"); }

    private void myDataGridView_UserDeletedRow (object sender, DataGridViewRowEventArgs e) { e.Row.DefaultCellStyle.BackColor = ColorTranslator.FromHtml("#FFCC99"); }

    private void myDataGridView_CellValueChanged (object sender, DataGridViewCellEventArgs e) { myDataGridView[e.ColumnIndex, e.RowIndex].DefaultCellStyle.BackColor = ColorTranslator.FromHtml("#FFFF99"); }

Vivek
The code formatter/syntax highlighter doesn't seem to be working!
Vivek
@Vivek: thanks. The display-option for different DataRowStates in the DataView was exaclty what i was looking for.
Viper