Updating the form's fields

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?VmFuZXNzYQ==?=

    Updating the form's fields

    Hi All!

    I am with a situation where I am not getting the right updating to the
    form's fields. The situation is the following one:

    I have one combobox and one textbox. I am using the CurrentChanged event of
    the BindingSource of the combobox to update the textbox. When selecting an
    item in the combobox or when selecting a row in the grid, it is updating the
    textbox correctly. The problem is when I apply a filter in the grid, and then
    the grid has no rows. I already made the following attempts:

    - When there is no row in the grid, the event is not called, and textbox
    mantains the previous content;
    - If I call the CurrentChanged event directly when there is no rows in the
    grid, in this case I clean up the textbox, but when I apply a filter again in
    the grid and the position of the combobox does not modify (that is, it is in
    the same register), the CurrentChanged is not called, and edit is blank
    (because I cleaned before);
    - I already tried to use “combo.Select edIndex = -1” but also did not worked.

    Does someone has any idea of how can I solve this situation?

    Thank you for any suggestion!
    Vanessa
  • =?Utf-8?B?TW9ydGVuIFdlbm5ldmlrIFtDIyBNVlBd?=

    #2
    RE: Updating the form's fields

    Hi Vanessa,

    I suspect you get some invalid data breaking the databinding. Try handling
    the DataError event of the BindingSource.

    It is a bit unclear what you have databound and not, and in fact what
    controls you have. What is the relationship between the (data)grid and the
    combobox? Are you databinding a ComboBox to one BindingSource and a DataGrid
    to another, while the TextBox remains unbound and is updated manually when a
    change occurs in either the ComboBox or the DataGrid?

    Other things to try. Bind the TextBox to the same BindingSource as the
    ComboBox rather than updating it in the CurrentChanged event (although this
    won't work if you use the same TextBox to display values from another
    BindingSource as well). Try handling the ListChanged event, which should
    fire if the underlying datasource changes. If the list is changed, get the
    BindingSource.C urrent value and update the TextBox accordingly.



    --
    Happy Coding!
    Morten Wennevik [C# MVP]


    "Vanessa" wrote:
    Hi All!
    >
    I am with a situation where I am not getting the right updating to the
    form's fields. The situation is the following one:
    >
    I have one combobox and one textbox. I am using the CurrentChanged event of
    the BindingSource of the combobox to update the textbox. When selecting an
    item in the combobox or when selecting a row in the grid, it is updating the
    textbox correctly. The problem is when I apply a filter in the grid, and then
    the grid has no rows. I already made the following attempts:
    >
    - When there is no row in the grid, the event is not called, and textbox
    mantains the previous content;
    - If I call the CurrentChanged event directly when there is no rows in the
    grid, in this case I clean up the textbox, but when I apply a filter again in
    the grid and the position of the combobox does not modify (that is, it is in
    the same register), the CurrentChanged is not called, and edit is blank
    (because I cleaned before);
    - I already tried to use “combo.Select edIndex = -1” but also did not worked.
    >
    Does someone has any idea of how can I solve this situation?
    >
    Thank you for any suggestion!
    Vanessa

    Comment

    • =?Utf-8?B?VmFuZXNzYQ==?=

      #3
      RE: Updating the form's fields

      Hi Morten!

      Let me explain better what I want to do.

      My database has the following tables:

      Table A - the main table that is shown in the form. It has a field that is a
      key into Table B;
      Table B - it is related to Table A and it is a combobox in the form. It has
      a field that is a key into Table C;
      Table C - it is related to Table B and it has a description field to show in
      a textbox.

      So, my question is, how can I make the binding to the textbox that is on
      Table C? What I want is to show the description field from Table C, whose key
      is on the Table B (combobox).

      Thank you,
      Vanessa

      "Morten Wennevik [C# MVP]" wrote:
      Hi Vanessa,
      >
      I suspect you get some invalid data breaking the databinding. Try handling
      the DataError event of the BindingSource.
      >
      It is a bit unclear what you have databound and not, and in fact what
      controls you have. What is the relationship between the (data)grid and the
      combobox? Are you databinding a ComboBox to one BindingSource and a DataGrid
      to another, while the TextBox remains unbound and is updated manually when a
      change occurs in either the ComboBox or the DataGrid?
      >
      Other things to try. Bind the TextBox to the same BindingSource as the
      ComboBox rather than updating it in the CurrentChanged event (although this
      won't work if you use the same TextBox to display values from another
      BindingSource as well). Try handling the ListChanged event, which should
      fire if the underlying datasource changes. If the list is changed, get the
      BindingSource.C urrent value and update the TextBox accordingly.
      >
      >
      >
      --
      Happy Coding!
      Morten Wennevik [C# MVP]
      >
      >
      "Vanessa" wrote:
      >
      Hi All!

      I am with a situation where I am not getting the right updating to the
      form's fields. The situation is the following one:

      I have one combobox and one textbox. I am using the CurrentChanged event of
      the BindingSource of the combobox to update the textbox. When selecting an
      item in the combobox or when selecting a row in the grid, it is updating the
      textbox correctly. The problem is when I apply a filter in the grid, and then
      the grid has no rows. I already made the following attempts:

      - When there is no row in the grid, the event is not called, and textbox
      mantains the previous content;
      - If I call the CurrentChanged event directly when there is no rows in the
      grid, in this case I clean up the textbox, but when I apply a filter again in
      the grid and the position of the combobox does not modify (that is, it is in
      the same register), the CurrentChanged is not called, and edit is blank
      (because I cleaned before);
      - I already tried to use “combo.Select edIndex = -1” but also did not worked.

      Does someone has any idea of how can I solve this situation?

      Thank you for any suggestion!
      Vanessa

      Comment

      Working...