473,320 Members | 2,024 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,320 software developers and data experts.

bindingcontext question

I have a question on bindingcontext, bindings, and
controlbindingscollection. I understand the very basic idea, and I think I
should be able to do this, but I'm not sure how.

First problem: I have a combobox and a textbox on a form. I also have a
"Customers" table loaded into a dataset. I set the combobox.datasource to
the table in the dataset, and add a binding to the text property of the
combobox for the 'Name' field. I also add a binding to the textbox.text
property for 'Address' like this:
combobox.databindings.add(new binding("text", ds.tables("customer"),
"Name"))
combobox.datasource = ds.tables("customer")
textbox.databindings.add(new binding("text", ds.tables("customer"),
"Address"))

When run the combobox has the first name in the table, and the proper
address. I can use the dropdown to select a new name, but when I do the
address in the textbox does not change. Question: what do I need to do to
get the textbox to display the correct address after selecting a name in
the combobox?

Second Situation: I would like to present data in 2 different ways, each
presentation would be on a different 'tab' . The first presentation would
basically be what I said before.. a combobox for selecting a record, and a
bunch of textboxes that list the info for the record selected in the
combobox. The second tab screen would be in the form of a datagrid that
lists all of the records. I would do a datagrid.datasource =
ds.tables("customer"). Here is where I'm a little confused... how can I
link the 2 views of the data. That is, when on the data grid, if the user
selects a row or a cell, and then switches back to the 1st view, the record
he chose in the datagrid is the record that will be displayed in the
combobox and textboxes. Likewise, if the user selects a record in the
combobox and switches to the datagrid tab, the row selected in the grid will
be the record he chose in the combobox.

Is there some way to do this synchronization automatically via the
currencymanager or databindings? Or is it something that needs to be done
manually.

Thanks for any advise... I'm still learning!

John

Nov 21 '05 #1
2 1980
JohnR,

I never succeeded in binding the text in a combobox.

If you succeed (completely) give than a message.

This is one of the few problems that I have asked help for in this newsgroup
and the newsgroup vb.controls. I seldom got an answer, some of them did not
even get a reply and the replies did not help me.

In some situations it will help if you use the selectedvalue property.
However, as well not in all. It depend as well what event you use.

Therefore don't expect to much help here in this binding question about the
combobox. (You can use dummy textboxes than it works)

In my opinion it can really act very strange.

Cor
Nov 21 '05 #2
Hi,

"JohnR" <Jo******@hotmail.com> wrote in message
news:2QZ2f.1126$t43.578@trndny02...
I have a question on bindingcontext, bindings, and
controlbindingscollection. I understand the very basic idea, and I think I
should be able to do this, but I'm not sure how.

First problem: I have a combobox and a textbox on a form. I also have a
"Customers" table loaded into a dataset. I set the combobox.datasource to
the table in the dataset, and add a binding to the text property of the
combobox for the 'Name' field. I also add a binding to the textbox.text
property for 'Address' like this:
combobox.databindings.add(new binding("text", ds.tables("customer"),
"Name"))
combobox.datasource = ds.tables("customer")
textbox.databindings.add(new binding("text", ds.tables("customer"),
"Address"))

When run the combobox has the first name in the table, and the proper
address. I can use the dropdown to select a new name, but when I do the
address in the textbox does not change. Question: what do I need to do to
get the textbox to display the correct address after selecting a name in
the combobox?
If i understand i right, you don't need to bind the Text property of the
ComboBox but use the DisplayMember instead. You also have to bind the
ComboBox and TextBox to the same DataSource (either DataSet or DataTable,
don't mix them).

eg:

combobox.DataSource = ds.Tables("customer")
combobox.DisplayMember = "Name"

textbox.DataBindings.Add( "Text", ds.Tables("customer"), "Address" )

Both are bound to the same DataTable (customer part of the DataSet).
Therefore they will share the same CurrencyManager and they will navigate
together.

Second Situation: I would like to present data in 2 different ways, each
presentation would be on a different 'tab' . The first presentation would
basically be what I said before.. a combobox for selecting a record, and
a bunch of textboxes that list the info for the record selected in the
combobox. The second tab screen would be in the form of a datagrid that
lists all of the records. I would do a datagrid.datasource =
ds.tables("customer"). Here is where I'm a little confused... how can I
link the 2 views of the data. That is, when on the data grid, if the user
selects a row or a cell, and then switches back to the 1st view, the
record he chose in the datagrid is the record that will be displayed in
the combobox and textboxes. Likewise, if the user selects a record in
the combobox and switches to the datagrid tab, the row selected in the
grid will be the record he chose in the combobox.
Same here, just bind the DataGrid to the same DataSource, remember we used a
DataTable for the TextBox and ComboBox, so we have to do the same for the
DataGrid :

datagrid.DataSource = ds.Tables("customer")

Is there some way to do this synchronization automatically via the
currencymanager or databindings? Or is it something that needs to be done
manually.
If you bind different Controls to the (exact) same DataSource and the
Controls have the same BindingContext (which is the default within a Form)
then they will share the same CurrencyManager and navigate together.

HTH,
Greetings

Thanks for any advise... I'm still learning!

John

Nov 21 '05 #3

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

Similar topics

0
by: Carl | last post by:
Hi, I am trying to figure out the best approach for this simple scenario. I have one C# Windows application Form that consumes few web services for all data related function. In this form...
1
by: D. Yates | last post by:
Hi, I retrieved the employee table from the Pubs database into a single dataset called, dataSet12. I dropped two textbox controls and a datagrid control onto the same form and bound the...
0
by: Nathan Carroll | last post by:
Attempting to eliminate flicker showing (form) and hiding seems to have no effect as I have it below. if I move the lines: Me.Show() Me.ShowInTaskbar = True f.Close() to the end of the...
1
by: Edwin | last post by:
Hi, I created a dataform with the data form wizard which created some textboxes and 1 checkbox. When I add a row (see section "Add Row" for code) the newly added is not accessible. A label...
0
by: Donald | last post by:
Mostly, I get the currencymanager from the form.bindingcontext property. but I found that I can aslo get the same currencymanager from a textbox.bindingcontext, even though this textbox does not...
0
by: nina98765 | last post by:
Hi all I have a data-bound Windows form bound to a strongly-typed dataset. Upon opening the form, I would like to Find a specific record based on a parameter I've passed to the form, and display...
4
by: graham | last post by:
Hi all, I have a strange one, and being new to .NET, not sure if this is a bug and whether there is a work around. I have a form with databound textboxes.. In me general decs... Dim...
6
by: Aaron Smith | last post by:
I have a form, oddly enough the same one with the expression column that is giving me a headache, and on this form I have a dataset that has a couple of tables in it that are related. If I do a...
6
by: MeowCow | last post by:
I have created a UserControl that encapsulates a third party data grid. My goal was to create my own DataSource and DataMember properties that forward the binding to the third party grid, then use...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.