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

VS 2005 - ComboBox does not reset to blank on moving to record withempty value.

P: n/a
I'm not entirely sure how to describe this issue. I have a number of
ComboBoxes in my application which have their text properties bound to a
field in a data set. The items loaded in the ComboBox are not data bound
(they just use the built in collection property of the ComboBox), and
they are all set to use the DropDownList style. When moving from record
to record via a BindingNavigator or a DataGridView (in master/detail
format), the text ComboBox appropriately reflects the value of the field
in the database, so long as it is not null. However, if you pass from a
record which contained a non-null value in the field represented by the
ComboBox to one which contains a null value in the same field, the
ComboBox simply continues to display the last non-null value it held.

For example: I want users to be able to select a Prefix/Salutation (Mr.,
Mrs., etc...) for Members being stored in an application. If you move
from a record with prefix filled in (eg., Mr. John Smith), to one
without (eg., Jane Doe), the ComboBox will continue to display the "Mr."
prefix. If, however, you move to another record which contains a prefix
(eg., Dr. Robert Smith), it will correctly display the new value.

Is this intended behavior, and if so, is there an effective way to get
around it?

Thanks,
Matt
Dec 30 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hi Matt,

Thanks for your posting!

I have performed testing under your description, but I can't repro the
problem. So could you please supply a simple demo to help me narrowing down
the current issue? Thanks for your understanding! You can send your project
as zip format to my alias -- v-****@online.microsoft.com (remove .online).

I'm looking forward your mail!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support

Dec 30 '05 #2

P: n/a
Hi,

"Matt" <br**********@community.nospam> wrote in message
news:OM*************@TK2MSFTNGP12.phx.gbl...
I'm not entirely sure how to describe this issue. I have a number of
ComboBoxes in my application which have their text properties bound to a
field in a data set. The items loaded in the ComboBox are not data bound
(they just use the built in collection property of the ComboBox), and they
are all set to use the DropDownList style. When moving from record to
record via a BindingNavigator or a DataGridView (in master/detail format),
the text ComboBox appropriately reflects the value of the field in the
database, so long as it is not null. However, if you pass from a record
which contained a non-null value in the field represented by the ComboBox
to one which contains a null value in the same field, the ComboBox simply
continues to display the last non-null value it held.

For example: I want users to be able to select a Prefix/Salutation (Mr.,
Mrs., etc...) for Members being stored in an application. If you move from
a record with prefix filled in (eg., Mr. John Smith), to one without (eg.,
Jane Doe), the ComboBox will continue to display the "Mr." prefix. If,
however, you move to another record which contains a prefix (eg., Dr.
Robert Smith), it will correctly display the new value.

Is this intended behavior, and if so, is there an effective way to get
around it?
I can reproduce it, it appears that the (Data)Binding converts DBNull.Value
into an empty string for string properties but ComboBox.Text doesn't do
anything when set to an empty string and mode is DropDownList.

Workarounds:
Since the ComboBox list isn't databound, you could add an item like "---" to
the Items to indicate nothing is selected and then set ComboBox -
properties - (DataBindings) - (Advanced) - Text - NullValue to "---"
(without the quotes).

-Or attach an event to the Format event of the (Data)Binding and change
DBNull.Value into null:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

AddHandler ComboBox1.DataBindings("Text").Format, AddressOf
OnComboBox1Format
End Sub

Private Sub OnComboBox1Format(ByVal Sender As Object, ByVal e As
ConvertEventArgs)

If (e.Value Is DBNull.Value) Then e.Value = Nothing
End Sub
HTH,
Greetings

Thanks,
Matt

Dec 30 '05 #3

P: n/a
Thanks, that formatting event was exactly what I was looking for. Would
this be considered a bug (i.e., will it likely be fixed in patches), or
is it an intended feature of some sort?

Regards,
Matt

Bart Mermuys wrote:
Hi,

I can reproduce it, it appears that the (Data)Binding converts DBNull.Value
into an empty string for string properties but ComboBox.Text doesn't do
anything when set to an empty string and mode is DropDownList.

Workarounds:
Since the ComboBox list isn't databound, you could add an item like "---" to
the Items to indicate nothing is selected and then set ComboBox -
properties - (DataBindings) - (Advanced) - Text - NullValue to "---"
(without the quotes).

-Or attach an event to the Format event of the (Data)Binding and change
DBNull.Value into null:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

AddHandler ComboBox1.DataBindings("Text").Format, AddressOf
OnComboBox1Format
End Sub

Private Sub OnComboBox1Format(ByVal Sender As Object, ByVal e As
ConvertEventArgs)

If (e.Value Is DBNull.Value) Then e.Value = Nothing
End Sub
HTH,
Greetings
Thanks,
Matt


Dec 30 '05 #4

P: n/a
Hi,

"Matt" <br**********@community.nospam> wrote in message
news:eG*************@tk2msftngp13.phx.gbl...
Thanks, that formatting event was exactly what I was looking for. Would
this be considered a bug (i.e., will it likely be fixed in patches), or is
it an intended feature of some sort?
I like to believe it's a bug or at least a problem that needs to be fixed,
but i have no idea if there will be patches or anything like that.

Greetings


Regards,
Matt

Bart Mermuys wrote:
Hi,

I can reproduce it, it appears that the (Data)Binding converts
DBNull.Value into an empty string for string properties but ComboBox.Text
doesn't do anything when set to an empty string and mode is DropDownList.

Workarounds:
Since the ComboBox list isn't databound, you could add an item like "---"
to the Items to indicate nothing is selected and then set ComboBox -
properties - (DataBindings) - (Advanced) - Text - NullValue to "---"
(without the quotes).

-Or attach an event to the Format event of the (Data)Binding and change
DBNull.Value into null:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

AddHandler ComboBox1.DataBindings("Text").Format, AddressOf
OnComboBox1Format
End Sub

Private Sub OnComboBox1Format(ByVal Sender As Object, ByVal e As
ConvertEventArgs)

If (e.Value Is DBNull.Value) Then e.Value = Nothing
End Sub
HTH,
Greetings
Thanks,
Matt


Dec 30 '05 #5

P: n/a
Hi Matt,

Thanks for your reply!

I have received you demo and performed the current problem. It seems some
unexpected behavior was occurred for ComboBox control. So, I need more time
to debug the current project. Maybe I'll contact with Dev team for the
current issue, I sorry for inconvenience.

Thanks for your understanding!

Yuan Ren [MSFT]
Microsoft Online Support

Dec 31 '05 #6

P: n/a
Hi Matt,

Thanks for your patience!

I have performed the issue. I'm not very clear about why you both set the
data binding of the ComboBox control and use "AddRange" method in it. So I
don't think this is a best practice for winform control's data binding.

Otherwise, if you need to do this, I suggest you call the "AddRange" method
likes below:
this.myCB.Items.AddRange(new object[] {
"",
"Mr",
"Ms",
"Mrs",
"Dr"});
I mean you add a null value for matching some related value from database.
After my performing, it seems the application runs well.

I appreciate your understanding and hope the above information helps, if
you have any issues or concerns please let me know. I will be happy to be
of further assistance.

Regards,

Yuan Ren [MSFT]
Microsoft Online Support

Jan 3 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.