Solved

Adding new row to bound datatable

Posted on 2009-05-05
3
1,006 Views
Last Modified: 2012-05-06
Hi,

I have a datatable which is bound to a combobox and several textboxes.
The combobox is used to browse through the items, and the textboxes to modify/view the data.
This all works fine.

However, when adding a new row to the table, the combobox shows this new row, yet the bindingcontext does not change position when I select the value in the combobox. Therefore I cannot modify the new row added.

Any help would be apprciated,

Thanks.
The binding for example;
 
            medicinesTableAdapter1.Fill(mediupDataSet1.medicines);
 
            cboxSelect.DataSource = mediupDataSet1;
            cboxSelect.DisplayMember = "Medicines.english_name";
            cboxSelect.ValueMember = "Medicines.ID";
 
            tboxID.DataBindings.Add("Text", mediupDataSet1, "Medicines.ID");
            tboxActiveComponents.DataBindings.Add("Text", mediupDataSet1, "Medicines.active_component");
 
Adding a new row:
           
 this.BindingContext[mediupDataSet1, "Medicines"].EndCurrentEdit();
            DataRow _dr = mediupDataSet1.medicines.NewRow();
            _dr.BeginEdit();
            _dr["ID"] = (uint)(mediupDataSet1.medicines.Compute("Max(id)", "")) + 1;
            _dr["hebrew_name"] = "êèÕäÔ ×ÓéÔ";
            _dr.EndEdit();
            mediupDataSet1.medicines.Rows.Add(_dr);

Open in new window

0
Comment
Question by:Nemesis_0001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 4

Expert Comment

by:Wardy_01
ID: 24305881
rebind the grid to the newly modified datatable.
then set the selectedindex to the newly created row.
0
 

Author Comment

by:Nemesis_0001
ID: 24305899
There is no grid, only a combobox and some textboxes.
0
 
LVL 4

Accepted Solution

by:
Wardy_01 earned 500 total points
ID: 24373735
sorry my bad ... read it wrong.

If you design this as per the Microsoft recommended approach you should have all your databinding code in a databind method.

That means you do things in this order ...

1. load
2. databind
3  edit
4  databind
5  finish

you have to be careful with the order of events though, i used to get tripped up all the time with this stuff. Put a breakpoint on your value setting statements to make sure the new values are being correctly picked up.

And of course don't forget to call databind when you're done ... i can't see that anywhere.
Databind should update your binding context assuming your underlying dataset has been modified correctly.

Migth be worth checking the dataset after you modify it to make sure the data has been correctly committed.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
c# DateTime Format validation 4 88
c#, case, if 4 37
c# deserialize JSON from web service using JsonConvert 9 56
.NET Redemption/Outlook Examples 3 29
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question