Display deleted rows in DataGrid

G

Guest

Hello,

I use DataGrid that displays data from DataTable. When I delete a row, this
row disapears in DataGrid and changes it's status in DataTable.

I there any way how to display everything what's in DataTable?
I want that user will see all changes made and after clicking some "Commit"
button those changes will be saved into the database.

Thanks a lot
Vladimir
 
G

Guest

Hmmm.

Make the first cell a Delete checkbox. Click all the rows you want to
delete (make sure they can all be uniquely identified). Have a Command
button labeled Delete. As each check box is checked, add that row to a second
grid. On clicking the Delete button, do the delete.
 
G

Guest

Have a look at RowStateFilter. The following code displays unchanged, new,
modified and deleted rows.

DataView dataView = (DataView)((CurrencyManager)dataGrid1.BindingContext[
dataGrid1.DataSource, dataGrid1.DataMember ]).List;
dataView.RowStateFilter = System.Data.DataViewRowState.CurrentRows |
System.Data.DataViewRowState.Deleted;

Then I would use a custom DataGridTextBoxColumn class to colour the rows
depending on the RowState.

public class CustomDataGridTextColumn : DataGridTextBoxColumn
{
protected override void Paint(System.Drawing.Graphics g,
System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source,
int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush,
bool alignToRight)
{
Brush newForeBrush = null;
DataRow dataRow = ((DataView)source.List)[ rowNum ].Row;

switch (dataRow.RowState)
{
case DataRowState.Added:
newForeBrush = new SolidBrush(Color.Blue);
break;
case DataRowState.Deleted:
newForeBrush = new SolidBrush(Color.Red);
break;
case DataRowState.Modified:
newForeBrush = new SolidBrush(Color.Green);
break;
default:
break;
}

if (newForeBrush != null)
{
base.Paint(g, bounds, source, rowNum, backBrush, newForeBrush,
alignToRight);
newForeBrush.Dispose();
}
else
{
base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight);
}
}
}

Regards,
Phil.
 
G

Guest

Thanks a lot Phil,

this completely solved my problem.

Vladimir


Phil Williams said:
Have a look at RowStateFilter. The following code displays unchanged, new,
modified and deleted rows.

DataView dataView = (DataView)((CurrencyManager)dataGrid1.BindingContext[
dataGrid1.DataSource, dataGrid1.DataMember ]).List;
dataView.RowStateFilter = System.Data.DataViewRowState.CurrentRows |
System.Data.DataViewRowState.Deleted;

Then I would use a custom DataGridTextBoxColumn class to colour the rows
depending on the RowState.

public class CustomDataGridTextColumn : DataGridTextBoxColumn
{
protected override void Paint(System.Drawing.Graphics g,
System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source,
int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush,
bool alignToRight)
{
Brush newForeBrush = null;
DataRow dataRow = ((DataView)source.List)[ rowNum ].Row;

switch (dataRow.RowState)
{
case DataRowState.Added:
newForeBrush = new SolidBrush(Color.Blue);
break;
case DataRowState.Deleted:
newForeBrush = new SolidBrush(Color.Red);
break;
case DataRowState.Modified:
newForeBrush = new SolidBrush(Color.Green);
break;
default:
break;
}

if (newForeBrush != null)
{
base.Paint(g, bounds, source, rowNum, backBrush, newForeBrush,
alignToRight);
newForeBrush.Dispose();
}
else
{
base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight);
}
}
}

Regards,
Phil.


Vladimir Kasal said:
Hello,

I use DataGrid that displays data from DataTable. When I delete a row, this
row disapears in DataGrid and changes it's status in DataTable.

I there any way how to display everything what's in DataTable?
I want that user will see all changes made and after clicking some "Commit"
button those changes will be saved into the database.

Thanks a lot
Vladimir
 
G

Guest

Glad to be of some help.

Phil.

Vladimir Kasal said:
Thanks a lot Phil,

this completely solved my problem.

Vladimir


Phil Williams said:
Have a look at RowStateFilter. The following code displays unchanged, new,
modified and deleted rows.

DataView dataView = (DataView)((CurrencyManager)dataGrid1.BindingContext[
dataGrid1.DataSource, dataGrid1.DataMember ]).List;
dataView.RowStateFilter = System.Data.DataViewRowState.CurrentRows |
System.Data.DataViewRowState.Deleted;

Then I would use a custom DataGridTextBoxColumn class to colour the rows
depending on the RowState.

public class CustomDataGridTextColumn : DataGridTextBoxColumn
{
protected override void Paint(System.Drawing.Graphics g,
System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source,
int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush,
bool alignToRight)
{
Brush newForeBrush = null;
DataRow dataRow = ((DataView)source.List)[ rowNum ].Row;

switch (dataRow.RowState)
{
case DataRowState.Added:
newForeBrush = new SolidBrush(Color.Blue);
break;
case DataRowState.Deleted:
newForeBrush = new SolidBrush(Color.Red);
break;
case DataRowState.Modified:
newForeBrush = new SolidBrush(Color.Green);
break;
default:
break;
}

if (newForeBrush != null)
{
base.Paint(g, bounds, source, rowNum, backBrush, newForeBrush,
alignToRight);
newForeBrush.Dispose();
}
else
{
base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight);
}
}
}

Regards,
Phil.


Vladimir Kasal said:
Hello,

I use DataGrid that displays data from DataTable. When I delete a row, this
row disapears in DataGrid and changes it's status in DataTable.

I there any way how to display everything what's in DataTable?
I want that user will see all changes made and after clicking some "Commit"
button those changes will be saved into the database.

Thanks a lot
Vladimir
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top