By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,667 Members | 1,863 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,667 IT Pros & Developers. It's quick & easy.

Add new row from DataGrid to dataset

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
15 Replies


P: n/a
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
Nov 16 '05 #2

P: n/a
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

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

Nov 16 '05 #3

P: n/a
Dear friend
use BindingContext(ds.Tables[0]).EndCurrentEdit();

thanks,
Siju

--
Message posted via http://www.dotnetmonster.com
Nov 16 '05 #4

P: n/a

use this

EndCurrentEdit();

--
Message posted via http://www.dotnetmonster.com
Nov 16 '05 #5

P: n/a
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
Nov 16 '05 #6

P: n/a
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

Nov 16 '05 #7

P: n/a
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
Nov 16 '05 #8

P: n/a
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?
Nov 17 '05 #9

P: n/a
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
Nov 17 '05 #10

P: n/a
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.
Nov 17 '05 #11

P: n/a
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.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"eye5600" <ey*****@discussions.microsoft.com> wrote in message
news:D3**********************************@microsof t.com...
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.


Nov 17 '05 #12

P: n/a
> 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.
Nov 17 '05 #13

P: n/a
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().

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"eye5600" <ey*****@discussions.microsoft.com> wrote in message
news:9A**********************************@microsof t.com...
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.


Nov 17 '05 #14

P: n/a
> 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.

Nov 17 '05 #15

P: n/a
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" <ey*****@discussions.microsoft.com> wrote in message
news:B3**********************************@microsof t.com...
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.


Nov 17 '05 #16

This discussion thread is closed

Replies have been disabled for this discussion.