Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

First of all let me say that I am very new to .NET and C#

and I need help so please bear with me. I have a tree

control that is dynamically populated from a dataset of

two joined tables. When a node is selected a groupbox is

displayed on the right that has textboxes to display

fields in the data set from the selected row. The fields

are bound to the proper dataset column via the design

properties page. The selected node shows the group box and

then calls a method to populate the items in the group box

passing the primary key for that row in the table. All

this works fine the group box displays the appropriate

information for the selected tree node. However when I add

a update button and change any data the updates don't

happen and no errors, just no changes to the data. I had

thought that any fields bound to a dataset at design time

would automatically reflect thier changes in the dataset.

Here is the method that fills the groupbox:

private void FillMaterialData(string MatNo)

{

if(MatNo != null)

{

DataRow currentRow;

currentRow = dataSet11.MATERIALS.Rows.Find(MatNo);

materialGroupBox.Text = "Material No. = " + MatNo;

matNameTB.Text = System.Convert.ToString(currentRow

["MATNAME"]);

matDescTB.Text = System.Convert.ToString(currentRow

["MATDESC"]);

}

}

 

And here is the simple update event:

private void btnUpdate_Click(object sender,

System.EventArgs e)

{

sqlDataAdapter1.Update(dataSet11);

sqlDataAdapter2.Update(dataSet11);

MessageBox.Show("Data Updated!");

}

Thanks in advance for any help.

.

Posted

When the control boxes are bounded to dataitems, first you should end the edit to the control boxes, so that the changes are reflected to the dataset and then you should use update() method to update the datasource.

 

To do that use the bindingmanagerbase class, and binding context method.

 

 

First declare the BindingManagerBase class and bind as

 

dim bind_mb as BindingManagerBase

bind_mb=me.bindingconext(dataset,"tablename")

 

 

And in the update event,

 

me.bindingcontext(dataset,"tablename").EndCurrentEdit()

 

adapter1.Update(dataset,"TableName").

 

 

 

Hope this would help.

Rufus
Posted
Thanks for your help. It is working know but I must have to do some binding in the groupbox fill method because it only updates the record for the first treenode selected. If you go to another node and update it updates the first one selected. Thanks again!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...