DataRow Rowstate and drag and drop

  • Thread starter Thread starter John Sitka
  • Start date Start date
J

John Sitka

crosspost but I have a feeling W.G. Ryan may know a trick.

windowsforms 1.1

Hi,

I'm displaying a datagrid
when the user enters (highlights) a certain text cell on a row it does a lookup of possible matches.
The matches are displayed in a listbox and one of those matches can be quickly tossed with the mouse
over to the grid surface and replace the original cell text.

In the datagrids DragDrop event I'm using BeginEdit() EndEdit() on the Row where the change takes place.
But this does not leave the DataSets Rowstate for that Row as Modified?

I hoped to use the rowstate as a condition for updates (one or many)

The grid works (Rowstate is correct) when the certain text cell that is the source of the lookup is keyboard edited or other grid
type functions.

How to solve?
 
Cruel wicked fate.....

Tip 9: More Control Over RowState
ADO.NET 2.0 provides two new methods to provide greater control over a DataRow's RowState: SetAdded and SetModified. These methods
set the RowState property of a DataRow, which was a read-only property in ADO.NET 1.0.

// Developer can use these to set the RowState
// of an unchanged row
oMyDataRow.SetAdded();
oMyDataRow.SetModified();

Yep,Here is what I have now.private void uxdgCadQuick_DragDrop(object sender, System.Windows.Forms.DragEventArgs
e){//lastuxdgCadQuickClickRow,lastuxdgCadQuickClickCol are form class level fields that remember the special column cellDataGrid
myGrid = (DataGrid)sender;DataGrid.HitTestInfo myHitInfo = myGrid.HitTest(e.X,
e.Y);uxdgCadQuick[lastuxdgCadQuickClickRow,lastuxdgCadQuickClickCol] =
e.Data.GetData(DataFormats.Text).ToString();dsCadQuick.Tables[0].Rows[lastuxdgCadQuickClickRow].BeginEdit();dsCadQuick.Tables[0].Rows[lastuxdgCadQuickClickRow]["partno"]
=
e.Data.GetData(DataFormats.Text).ToString();dsCadQuick.Tables[0].Rows[lastGridClickRow].EndEdit();uxdgCadQuick.SelectionBackColor.ToKnownColor();
}This works in that the Datagrid and Datatable DataRow exists with the changed infobut I can't go back say after a couple more
edits and get the set of all rows inthat datatable and find which ones have changed and Update either via aDataAdapter or with my
own Update commands.Thanks for the link, I don't get it yet though, but just started trying."Cor Ligthert [MVP]"
John,

Have a look in 1.1 to EndCurrentEdit.

http://msdn.microsoft.com/library/d...mscurrencymanagerclassendcurrentedittopic.asp

AFAIK is this problem in 2.0 gone.

I hope this helps,

Cor
 
WOW crappy formatting...

Anyways is the gist of it to use this hunk from the link you provided

CurrencyManager gridCurrencyManager =
(CurrencyManager)this.BindingContext
[dataGrid1.DataSource, dataGrid1.DataMember];
gridCurrencyManager.EndCurrentEdit();

as a replacement for

DataSet.Tables[0].Rows[<the edited row>].EndEdit



Reformatted.....

Here is what I have now.
private void uxdgCadQuick_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
//lastuxdgCadQuickClickRow,lastuxdgCadQuickClickCol are form class level fields that remember the special column cell
DataGrid myGrid = (DataGrid)sender;
DataGrid.HitTestInfo myHitInfo = myGrid.HitTest(e.X,e.Y);
uxdgCadQuick[lastuxdgCadQuickClickRow,lastuxdgCadQuickClickCol] = e.Data.GetData(DataFormats.Text).ToString();
dsCadQuick.Tables[0].Rows[lastuxdgCadQuickClickRow].BeginEdit();
dsCadQuick.Tables[0].Rows[lastuxdgCadQuickClickRow]["partno"] = e.Data.GetData(DataFormats.Text).ToString();
dsCadQuick.Tables[0].Rows[lastGridClickRow].EndEdit();
uxdgCadQuick.SelectionBackColor.ToKnownColor();
}

This works in that the Datagrid and Datatable DataRow exists with the changed infobut I can't go back say after a couple more
edits and get the set of all rows inthat datatable and find which ones have changed and Update either via aDataAdapter or with my
own Update commands.Thanks for the link, I don't get it yet though, but just started trying."





John Sitka said:
Cruel wicked fate.....

Tip 9: More Control Over RowState
ADO.NET 2.0 provides two new methods to provide greater control over a DataRow's RowState: SetAdded and SetModified. These methods
set the RowState property of a DataRow, which was a read-only property in ADO.NET 1.0.

// Developer can use these to set the RowState
// of an unchanged row
oMyDataRow.SetAdded();
oMyDataRow.SetModified();

Yep,Here is what I have now.private void uxdgCadQuick_DragDrop(object sender, System.Windows.Forms.DragEventArgs
e){//lastuxdgCadQuickClickRow,lastuxdgCadQuickClickCol are form class level fields that remember the special column cellDataGrid
myGrid = (DataGrid)sender;DataGrid.HitTestInfo myHitInfo = myGrid.HitTest(e.X,
e.Y);uxdgCadQuick[lastuxdgCadQuickClickRow,lastuxdgCadQuickClickCol] =
e.Data.GetData(DataFormats.Text).ToString();dsCadQuick.Tables[0].Rows[lastuxdgCadQuickClickRow].BeginEdit();dsCadQuick.Tables[0].Rows[lastuxdgCadQuickClickRow]["partno"]
=
e.Data.GetData(DataFormats.Text).ToString();dsCadQuick.Tables[0].Rows[lastGridClickRow].EndEdit();uxdgCadQuick.SelectionBackColor.ToKnownColor();
}This works in that the Datagrid and Datatable DataRow exists with the changed infobut I can't go back say after a couple more
edits and get the set of all rows inthat datatable and find which ones have changed and Update either via aDataAdapter or with my
own Update commands.Thanks for the link, I don't get it yet though, but just started trying."Cor Ligthert [MVP]"
 
Thanks.
The link you provided is an improvement and did address what I needed.

basically
CurrencyManager gridCurrencyManager =
(CurrencyManager)this.BindingContext
[dataGrid1.DataSource, dataGrid1.DataMember];
gridCurrencyManager.EndCurrentEdit();
is a replacement for

DataSet.Tables[0].Rows[<the edited row>].EndEdit();

I still can't quite get things perfect because the Edit of the cell when generated by a
DragDrop using DragDropEffects.Copy still dosen't explicitly drive the row editing events
in a similar way as selecting a cell with a mouse of tabbing and editing cells with a keyboard. (pencil/arrow in row header)
Thus after the Edit is made via DragandDrop the RowState is still not set to "modified" until
the DataGrid row is changed by some GUI event, and I can't seem to find the navigation technique
to an available "parked" position in a Datagrid which drives that RowState commitment.




Thanks again. Cor Ligthert [MVP]








Cor Ligthert said:
John,

Have a look in 1.1 to EndCurrentEdit.

http://msdn.microsoft.com/library/d...mscurrencymanagerclassendcurrentedittopic.asp

AFAIK is this problem in 2.0 gone.

I hope this helps,

Cor
 
Back
Top