changes in datarow update GUI

Hi experts

I'm a bit confused right now, hope you can help me.
I have a bindingsource which points to datatable (quite standard)
several fields of my datarow/databale points to different controls.

How can I acchieve that a change directly in my datarow is reflected in my gui. Do I have to do that myself?

example:
mydatarow["field1"] = "test";

should update the corresponding textfield
LVL 3
ArikaelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ToddBeaulieuCommented:
They should, if you have the bindings set up correctly.

I'm not sure what you mean by the datarow points to controls. It should be the other way around.

Can you share the code that creates the control bindings?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ArikaelAuthor Commented:
hi

yeah, you are right the control points to the datarow respectivly the bindingsource of course.
so, the code
mydatarow["field1"] = "test";

should update the corresponding control?
0
ToddBeaulieuCommented:
Right, but only if you've set the binding up correctly. If, for instance, you populated the control with something like "Control.Text = mydatarow["field1"]", you haven't established a binding at all.

That's why I wanted to verify that the binding is correct.
0
ArikaelAuthor Commented:
hi

the binding is like:
this.JobFreeTextTextBox.DataBindings.Add("Text", this.MetaBindingSource, "JobFreeText", false, DataSourceUpdateMode.OnPropertyChanged);

I suspect that there is a problem elsewhere in the code
0
ToddBeaulieuCommented:
I just worked up a super simple example that shows basic binding does in fact do what you're looking for. I don't think your binding is correct.

This doesn't use a database. Trying to keep it as simple as possible.

Upon startup the textbox correctly shows "Zebra Tech". When I hit the button, the textbox changes to "New Company".
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace C_WinForms_Quick_Tests
{
    public partial class Form1 : Form
    {
        private DataSet ds;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            SetBindings();
        }

        private void SetBindings()
        {
            ds = new DataSet("Customers");

            using (DataTable custTable = new DataTable("custTable"))
            {
                custTable.Columns.Add("CustomerName", typeof(string));

                ds.Tables.Add(custTable);

                custTable.Rows.Add( "Zebra Tech" );

                textBox1.DataBindings.Add("Text", ds, "custTable.CustomerName");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ds.Tables["custTable"].Rows[0]["CustomerName"] = "New Company";
        }

    }
}

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.