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

RE: Display deleted rows in DataGrid by mklapp

mklapp
Mon Oct 18 09:19:04 CDT 2004

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.


"Vladimir Kasal" wrote:

> 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

RE: Display deleted rows in DataGrid by PhilWilliams

PhilWilliams
Mon Oct 18 16:03:02 CDT 2004

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" wrote:

> 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

RE: Display deleted rows in DataGrid by VladimirKasal

VladimirKasal
Tue Oct 19 01:11:01 CDT 2004

Thanks a lot Phil,

this completely solved my problem.

Vladimir


"Phil Williams" wrote:

> 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" wrote:
>
> > 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

RE: Display deleted rows in DataGrid by PhilWilliams

PhilWilliams
Tue Oct 19 03:15:03 CDT 2004

Glad to be of some help.

Phil.

"Vladimir Kasal" wrote:

> Thanks a lot Phil,
>
> this completely solved my problem.
>
> Vladimir
>
>
> "Phil Williams" wrote:
>
> > 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" wrote:
> >
> > > 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