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

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

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
6 4864
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Nicolae Fieraru | last post by:
Hi All, I am trying to change the rowsource of a combobox when I click on it. I played with many events, associated with the form and the combobox, but still haven't figured out what is the way...
8
by: Zlatko Matiæ | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
7
by: charliewest | last post by:
Using .Net CF, i have created a 2 dimension ArrayList, and "binded" this list to a ComboBox control using the "DataSource" property. I have set the DisplaySource and ValueMember properties as well....
2
by: Agnes | last post by:
My code is so simple to reset the text or set text to blank after the user choose the value in combobox. Private Sub cboBLData_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As...
0
by: dbuchanan | last post by:
ComboBox databindng Problem == How the ComboBox is setup and used: My comboBox is populated by a lookup table. The ValueMember is the lookup table's Id and the DisplayMember is the text from a...
4
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box...
5
by: Steve B. | last post by:
Without adding whitespace to the ComboBox datasource is there a way I can add a blank entry or, a reset entry, to the ComboBox dropdown Thanks Steve
2
by: shumaker | last post by:
I have a combobox that is very much like the one found in the RSS project here: http://msdn.microsoft.com/vstudio/express/visualCSharp/learning/ My projectNameComboBox basically is filled with a...
2
by: PotatoChip | last post by:
I have created a form which has, in the form header, a combobox which looks up the values (eg. Error #) in the form and will either take the user to the record which matches the looked up value or,...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...
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)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.