By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,660 Members | 1,560 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,660 IT Pros & Developers. It's quick & easy.

Updating the form's fields

P: n/a
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.SelectedIndex = -1” but also did not worked.

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

Thank you for any suggestion!
Vanessa
Mar 11 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.Current 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.SelectedIndex = -1” but also did not worked.

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

Thank you for any suggestion!
Vanessa
Mar 12 '08 #2

P: n/a
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.Current 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.SelectedIndex = -1” but also did not worked.

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

Thank you for any suggestion!
Vanessa
Mar 12 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.