Datagrid new row update problem.

B

BFX

Hi All,

I have datagrid with binding on dataset
this.grdMachineType.DataMember = "MachineTypes";

this.grdMachineType.DataSource = this.dsMachineTypes;



After append new row in datagrid i call this

private void tbMachineTypes_ButtonClick(object sender,
System.Windows.Forms.ToolBarButtonClickEventArgs e)

{

this.grdMachineType[this.grdMachineType.CurrentRowIndex,1] = false;

this.dsMachineTypes.GetChanges();

this.grdMachineType.BindingContext[this.dsMachineTypes.MachineTypes].EndCurr
entEdit();

this.daMachineT.Update(this.dsMachineTypes.MachineTypes);

this.dsMachineTypes.AcceptChanges();

}

but databze haven't any changes .

If I after adding new row select another row and call save
tbMachineTypes_ButtonClick row is added.

thank's in advance for help

BFX
 
B

BFX

After tests i know that problem is when user dont press enter after insert
value to datagrid cell.
I try use
SendKeys.Send("{ENTER}");

but it's without any reason.

Could anyone help with this problem?

thanks
 
C

Cor Ligthert

BFX.
this.dsMachineTypes.GetChanges();

this.grdMachineType.BindingContext[this.dsMachineTypes.MachineTypes].EndCurr
entEdit();

When you do the EndCurrentEdit than the dataset can probably get changes.

Therefore I would change these two rows from position.

Don't nock to hard on your head when you read this, I don't see often
directly this kind of mistakes in my own programs.

I hope this helps,

Cor
 
B

BFX

Thaks for answer but I think problem is that dataset cannot get changes when
user dont't press enter after edit datagrid cell.
But I don't see why EndCurrentEdit and SendKeys.Send("{ENTER}"); don't cause
End Editing process on datagrid.

Cor Ligthert said:
BFX.
this.dsMachineTypes.GetChanges();

this.grdMachineType.BindingContext[this.dsMachineTypes.MachineTypes].EndCurr
entEdit();

When you do the EndCurrentEdit than the dataset can probably get changes.

Therefore I would change these two rows from position.

Don't nock to hard on your head when you read this, I don't see often
directly this kind of mistakes in my own programs.

I hope this helps,

Cor
 
C

Cor Ligthert

BFX

I see some strange code in what you show, however see this sample.

See this sample
You have in your datagrid
1
3
5
When the users changes the 3 in a 4 and clicks the button, nothing happens
in the datagrid and in the dataset until that he changes the row or there is
done an endcurrentedit on the right datasource, what forces to push the
changes down in the datasource accoording to the bindingcontext.

There is in my opinion some strange code in what you show. I did not see it
the first time.

this.dsMachineTypes.GetChanges();
This is a result and would normally be after the endcurrentedit

If (this.dsMachineTypes.HasChanges())
DataSet dsChanges = this.dsMachineTypes.GetChanges();

(And than do the update with that dsChanges. Than the acceptchanges on the
original dataset is needed because the dataset with changes is a copy. In
the way you show it now with the original dataset is the acceptchanges
already done by the dataadapter)

I hope this helps,

Cor





BFX said:
Thaks for answer but I think problem is that dataset cannot get changes
when
user dont't press enter after edit datagrid cell.
But I don't see why EndCurrentEdit and SendKeys.Send("{ENTER}"); don't
cause
End Editing process on datagrid.

Cor Ligthert said:
BFX.
this.dsMachineTypes.GetChanges();

this.grdMachineType.BindingContext[this.dsMachineTypes.MachineTypes].EndCurr
entEdit();

When you do the EndCurrentEdit than the dataset can probably get changes.

Therefore I would change these two rows from position.

Don't nock to hard on your head when you read this, I don't see often
directly this kind of mistakes in my own programs.

I hope this helps,

Cor
 
B

BFX

Thank's Cor,

but solving of my problem was easy, see folow

this.dsMachineTypes.AcceptChanges();

grdMachineType.CurrentRowIndex = -1; // it's :)

this.grdMachineType.BindingContext[this.dsMachineTypes.MachineTypes].EndCurr
entEdit();

this.daMachineT.Update(this.dsMachineTypes.MachineTypes);



Cor Ligthert said:
BFX

I see some strange code in what you show, however see this sample.

See this sample
You have in your datagrid
1
3
5
When the users changes the 3 in a 4 and clicks the button, nothing happens
in the datagrid and in the dataset until that he changes the row or there is
done an endcurrentedit on the right datasource, what forces to push the
changes down in the datasource accoording to the bindingcontext.

There is in my opinion some strange code in what you show. I did not see it
the first time.

this.dsMachineTypes.GetChanges();
This is a result and would normally be after the endcurrentedit

If (this.dsMachineTypes.HasChanges())
DataSet dsChanges = this.dsMachineTypes.GetChanges();

(And than do the update with that dsChanges. Than the acceptchanges on the
original dataset is needed because the dataset with changes is a copy. In
the way you show it now with the original dataset is the acceptchanges
already done by the dataadapter)

I hope this helps,

Cor





BFX said:
Thaks for answer but I think problem is that dataset cannot get changes
when
user dont't press enter after edit datagrid cell.
But I don't see why EndCurrentEdit and SendKeys.Send("{ENTER}"); don't
cause
End Editing process on datagrid.

Cor Ligthert said:
BFX.


this.dsMachineTypes.GetChanges();
this.grdMachineType.BindingContext[this.dsMachineTypes.MachineTypes].EndCurr
entEdit();


When you do the EndCurrentEdit than the dataset can probably get changes.

Therefore I would change these two rows from position.

Don't nock to hard on your head when you read this, I don't see often
directly this kind of mistakes in my own programs.

I hope this helps,

Cor
 
C

Cor Ligthert

Thank's Cor,
but solving of my problem was easy, see folow
this.dsMachineTypes.AcceptChanges();
grdMachineType.CurrentRowIndex = -1; // it's :)
this.grdMachineType.BindingContext[this.dsMachineTypes.MachineTypes].EndCurr
entEdit();
this.daMachineT.Update(this.dsMachineTypes.MachineTypes);
And you are sure that with this code, when somebody changing first the rows
in the grid before clicking on the button, update the changes.

It will in my opinion be a miracle however when you say so. For the rest it
is accoording what I tried to tell you all the time, where I was thinking
that you were updating using the getchanges method.

In this way will withouth that acceptchanges probably this enough.
\\\
BindingContext[dsMachineTypes.MachineTypes].EndCurrentEdit();
////

Cor
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top