Add new row from DataGrid to dataset

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All,
I have dataGrid and as its datasource is dataset. When I edit ne row, I have
to click on the next (or previous) row to this (new)row will be add into the
dataset. That is problem , if user add new row and immediate save the
dataset. in this scenario the new row don't add into the dataset.

Any sugestion?

Thanx

Honza
 
Jan,

One of the most asked questions in relation to ADONET.

The data in the datagrid is pushed down to the datasource after a rowchange.
You can force that with (here showed for the first table)

BindingContext(ds.Tables[0]).EndCurrentEdit();

I hope this helps

Cor
 
Dear Cor,
thank you for you heko. But I didn't follow your think. I don't know How can
I use this method:
EndCurrentEdit();

Thank you again Cor,


Jan
 
Dear friend
use BindingContext(ds.Tables[0]).EndCurrentEdit();

thanks,
Siju
 
Jan,

What is the problem with it, you need to set that before the place you want
to get information from a datarow according the last changed datagridrow
without that you did a row change in the datagrid.

BindingContext(ds.Tables[0]).EndCurrentEdit();

Where I wrote that ds.Table[0] is in this case the first table. However can
be of course any table or dataview.

What is the problem,
I don't see it.

Cor
 
Cor,
when i used this

BindingContext(ds.Tables[0]).EndCurrentEdit();

I received error:
error CS0118: 'System.Windows.Forms.Control.BindingContext' denotes a
'property' where a 'method' was expected


So I tried to use this:

BindingContext[ds.Tables[0]].EndCurrentEdit();

it's look much better, because compiler doesn't show any error, but new row
doesn't save into dataset.....


I know, mistakes is on my side, but i don' t know where.....


Thanks

Jan
 
Jan,

BindingContext[ds.Tables[0]].EndCurrentEdit();

This is not the first time I make this mistake and forget that it is a
collection of bindingcontextes.

Sorry

Cor
 
BindingContext[ds.Tables[0]].EndCurrentEdit();

This does not work for me either. I think the DataBinding must have to be
explicitly set somewhere, but I don't see where. Ideas?
 
Jan,

When the user does not click on the little pencil to confirm the update,
than it will never be done. I was involved in a long thread in another
newsgroup because that was not done.

Cor
 
Cor: I wonder if you are thinking of web forns, not windows forms.

I had better luck using the name of the table "data_path." :

BindingContext[dsPaths,"data_paths"].EndCurrentEdit() ;

It saved the row, but did not capture the data from the last cell. It worked
better when I forced the column to change:

dgPaths.CurrentCell = new DataGridCell(dgPaths.CurrentCell.RowNumber,
1-dgPaths.CurrentCell.ColumnNumber);
BindingContext[dsPaths,"data_paths"].EndCurrentEdit() ;

This is impossibly clumsy. The language designers must have had some
non-hack solution in mind to such an ordinary situation.
 
Hi,

You are on the right track, but instead of moving grid focus to another
cell, I'd suggest that you use the grid's EndEdit() method.
 
You are on the right track, but instead of moving grid focus to another
cell, I'd suggest that you use the grid's EndEdit() method.

Well, you know, I thought of that, but

dgPaths.EndEidt() ;

gives a compile error of
"Windows.Systems.Forms.DataGrid.EndEdit is inaccessible due to its
protection level."

despite the fact that EndEdit is offered as an option by Intellisense.
 
Derive a control from the datagrid and expose this protected method through
a public helper method.
The helper method can determine the current row and current column style
before calling the protected EndEdit().
 
Derive a control from the datagrid and expose this protected method through
a public helper method.
The helper method can determine the current row and current column style
before calling the protected EndEdit().

The method using the column style and row is not protected, so helper is not
required, and, I think won't work for other reasons. I wrote this:

private void AcceptText(){
DataGridColumnStyle dgc =
dgPaths.TableStyles[0].GridColumnStyles[dgPaths.CurrentCell.ColumnNumber] ;
dgPaths.EndEdit(dgc,dgPaths.CurrentCell.RowNumber,false ) ;
BindingContext[dsPaths,"data_paths"].EndCurrentEdit() ;
}

It seems to do the trick. On to the next problem.
 
That's actually the right way of committing editing in progress.
BTW, I was really surprised to know there is another protected overload of
EndEdit().

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]


eye5600 said:
Derive a control from the datagrid and expose this protected method
through
a public helper method.
The helper method can determine the current row and current column style
before calling the protected EndEdit().

The method using the column style and row is not protected, so helper is
not
required, and, I think won't work for other reasons. I wrote this:

private void AcceptText(){
DataGridColumnStyle dgc =
dgPaths.TableStyles[0].GridColumnStyles[dgPaths.CurrentCell.ColumnNumber]
;
dgPaths.EndEdit(dgc,dgPaths.CurrentCell.RowNumber,false ) ;
BindingContext[dsPaths,"data_paths"].EndCurrentEdit() ;
}

It seems to do the trick. On to the next problem.
 
Back
Top