473,395 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Binding data to controls?

Max

Hello,

I made a windows form with a combo box and 4 text boxes. All 5 objects should get their data from a data set which is populated
in the form load method. The combo box has item ids. When the users selects an item from the combo box I'd like the 4 text boxes to
get populated with the corresponding item information from the same dataset table row that the combo box is pulling it's info from.
Is there an easy way of doing this besides writing code to query the database based on the combo box id? (sample code will be
appreciated)

Cheers,
Max.

Jul 16 '07 #1
3 2426
Max,

As long as you are binding to the same data table, then you should have
no problem with the textboxes changing when you change the current record in
the combobox. Just make sure that the data table that you bind everything
to has the value that you show in the combobox, as well as the other values
you would show in the textboxes.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Max" <ma******@yahoo.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>
Hello,

I made a windows form with a combo box and 4 text boxes. All 5 objects
should get their data from a data set which is populated in the form load
method. The combo box has item ids. When the users selects an item from
the combo box I'd like the 4 text boxes to get populated with the
corresponding item information from the same dataset table row that the
combo box is pulling it's info from. Is there an easy way of doing this
besides writing code to query the database based on the combo box id?
(sample code will be appreciated)

Cheers,
Max.

Jul 16 '07 #2
Max

Can you give me an example because I can't seem to get this working. This is what I have:

cb_myCombo.DataSource = ds_myDS.Tables["X"];
cb_myCombo.DisplayMember = "A";
txt_myText1.DataBindings.Add("Text",ds_myDS,"Y");
txt_myText2.DataBindings.Add("Text",ds_myDS,"Z");
.....

Max


"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in message news:Oe**************@TK2MSFTNGP04.phx.gbl...
Max,

As long as you are binding to the same data table, then you should have
no problem with the textboxes changing when you change the current record in
the combobox. Just make sure that the data table that you bind everything
to has the value that you show in the combobox, as well as the other values
you would show in the textboxes.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Max" <ma******@yahoo.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>>
Hello,

I made a windows form with a combo box and 4 text boxes. All 5 objects
should get their data from a data set which is populated in the form load
method. The combo box has item ids. When the users selects an item from
the combo box I'd like the 4 text boxes to get populated with the
corresponding item information from the same dataset table row that the
combo box is pulling it's info from. Is there an easy way of doing this
besides writing code to query the database based on the combo box id?
(sample code will be appreciated)

Cheers,
Max.

Jul 16 '07 #3
Max,

The reason it doesn't work is because you are essentially binding to two
different data sources.

What makes a binding context unique is a combination of the data source
and the data member, both of which have to be the same to share the same
binding context. For your combo box, you have this:

DataSource - ds_myDS.Tables["X"]
DataMember - null

For the textboxes, this is your data source:

DataSource - ds_myDS
DataMember - "X"

Now, while they will both yield the same DataTable, the binding
infrastructure looks at them as two separate binding contexts, and that's
why they don't change.

You need to bind to the same thing, so you need to do this:

cb_myCombo.DataSource = ds_myDS;
cb_myCombo.DataMember = "X";
cb_myCombo.DisplayMember = "A";
txt_myText1.DataBindings.Add("Text",ds_myDS,"Y");
txt_myText2.DataBindings.Add("Text",ds_myDS,"Z");

Or do this:

cb_myCombo.DataSource = ds_myDS.Tables["X"];
cb_myCombo.DisplayMember = "A";
txt_myText1.DataBindings.Add("Text",ds_myDS.Tables["Y"], null);
txt_myText2.DataBindings.Add("Text",ds_myDS.Tables["Z"], null);
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Max" <ma******@yahoo.comwrote in message
news:eK****************@TK2MSFTNGP04.phx.gbl...
>
Can you give me an example because I can't seem to get this working. This
is what I have:

cb_myCombo.DataSource = ds_myDS.Tables["X"];
cb_myCombo.DisplayMember = "A";
txt_myText1.DataBindings.Add("Text",ds_myDS,"Y");
txt_myText2.DataBindings.Add("Text",ds_myDS,"Z");
....

Max


"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:Oe**************@TK2MSFTNGP04.phx.gbl...
>Max,

As long as you are binding to the same data table, then you should
have no problem with the textboxes changing when you change the current
record in the combobox. Just make sure that the data table that you bind
everything to has the value that you show in the combobox, as well as the
other values you would show in the textboxes.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Max" <ma******@yahoo.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>>>
Hello,

I made a windows form with a combo box and 4 text boxes. All 5 objects
should get their data from a data set which is populated in the form
load method. The combo box has item ids. When the users selects an item
from the combo box I'd like the 4 text boxes to get populated with the
corresponding item information from the same dataset table row that the
combo box is pulling it's info from. Is there an easy way of doing this
besides writing code to query the database based on the combo box id?
(sample code will be appreciated)

Cheers,
Max.
Jul 17 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ann Morris | last post by:
INTRODUCTION One of the most powerful aspects of .NET and Windows Forms is data binding. Data binding is the process of associating user interface (UI) elements with a data source to generate a...
1
by: JD Kronicz | last post by:
Hi .. I have an issue I have been beating my head against the wall on for some time. I am trying to use late binding for MS graph so that my end users don't have to worry about having the right...
1
by: matty.hall | last post by:
There's a lot of information out there about data-binding UI objects (i.e. derived from Control) to non-UI custom business objects. Is it possible to do the same without any UI being involved at...
0
by: popsovy | last post by:
Hi I have a question about whether Data Binding can facilitate the process of saving data in a web application I learned that you can data bind information from a number of different data...
5
by: Vigneshwar Pilli via DotNetMonster.com | last post by:
string connectionString1 = "server=(local); user=sa;password=sa; database=sonic"; System.Data.SqlClient.SqlConnection dbConnection1 = new System.Data.SqlClient.SqlConnection(connectionString1);...
4
by: Alan Silver | last post by:
Hello, I'm trying to use an ArrayList to do data binding, but am getting an error I don't understand. I posted this in another thread, but that was all confused with various other problems,...
11
by: Rourke Eleven | last post by:
I have looked and searched. What good is the databind property on Radiobuttons? How does one go about actually using it? What is a good resource on this? I understand that I can easily get/set...
0
by: Larry Serflaten | last post by:
I am not sure how many are aware of this sort of data binding, but as it is new to many (classic) VB developers I thought I would post this once just to let people know of its availablility. ...
19
by: Larry Lard | last post by:
In the old days (VB3 era), there was a thing called the Data Control, and you could use it to databind controls on forms to datasources, and so (as the marketing speak goes), 'create database...
3
by: Simon Tamman | last post by:
I've come across an interesting bug. I have workarounds but i'd like to know the root of the problem. I've stripped it down into a short file and hope someone might have an idea about what's going...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.