bindingcontext question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JohnR

    #1

    bindingcontext question

    I have a question on bindingcontext, bindings, and
    controlbindings collection. 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.dataso urce 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.databi ndings.add(new binding("text", ds.tables("cust omer"),
    "Name"))
    combobox.dataso urce = ds.tables("cust omer")
    textbox.databin dings.add(new binding("text", ds.tables("cust omer"),
    "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.dataso urce =
    ds.tables("cust omer"). 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



  • Cor Ligthert [MVP]

    #2
    Re: bindingcontext question

    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


    Comment

    • Bart Mermuys

      #3
      Re: bindingcontext question

      Hi,

      "JohnR" <JohnR104@hotma il.com> wrote in message
      news:2QZ2f.1126 $t43.578@trndny 02...[color=blue]
      >I have a question on bindingcontext, bindings, and
      >controlbinding scollection. 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.dataso urce 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.databi ndings.add(new binding("text", ds.tables("cust omer"),
      > "Name"))
      > combobox.dataso urce = ds.tables("cust omer")
      > textbox.databin dings.add(new binding("text", ds.tables("cust omer"),
      > "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?[/color]

      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.DataSo urce = ds.Tables("cust omer")
      combobox.Displa yMember = "Name"

      textbox.DataBin dings.Add( "Text", ds.Tables("cust omer"), "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.
      [color=blue]
      >
      > 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.dataso urce =
      > ds.tables("cust omer"). 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.[/color]

      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.DataSo urce = ds.Tables("cust omer")
      [color=blue]
      >
      > Is there some way to do this synchronization automatically via the
      > currencymanager or databindings? Or is it something that needs to be done
      > manually.[/color]

      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
      [color=blue]
      >
      > Thanks for any advise... I'm still learning!
      >
      > John
      >
      >
      >[/color]


      Comment

      Working...