473,593 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 BindingNavigato r 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 4901
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.mic rosoft.com (remove .online).

I'm looking forward your mail!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support

Dec 30 '05 #2
Hi,

"Matt" <br**********@c ommunity.nospam > wrote in message
news:OM******** *****@TK2MSFTNG P12.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 BindingNavigato r 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(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

AddHandler ComboBox1.DataB indings("Text") .Format, AddressOf
OnComboBox1Form at
End Sub

Private Sub OnComboBox1Form at(ByVal Sender As Object, ByVal e As
ConvertEventArg s)

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(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

AddHandler ComboBox1.DataB indings("Text") .Format, AddressOf
OnComboBox1Form at
End Sub

Private Sub OnComboBox1Form at(ByVal Sender As Object, ByVal e As
ConvertEventArg s)

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


Dec 30 '05 #4
Hi,

"Matt" <br**********@c ommunity.nospam > wrote in message
news:eG******** *****@tk2msftng p13.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(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

AddHandler ComboBox1.DataB indings("Text") .Format, AddressOf
OnComboBox1Form at
End Sub

Private Sub OnComboBox1Form at(ByVal Sender As Object, ByVal e As
ConvertEventArg s)

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
8497
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 of doing it. I have a table with products, tblProducts, some of them are Active while others are Inactive. The form shows all the products purchased by a customer, both Active and Inactive in a ComboBox, cbProducts. My client wants to view all...
8
12081
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 combobox. What is the solution? Thank you in advance.
7
20758
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. The control populates well, both the display values, and selected values. However, when i try to "set" the SelectedValue or SelectedIndex properties, nothing happens.... The default blank value in the ComboBox is always selected. My code is: ...
2
3291
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 System.EventArgs) Handles cboBLData.SelectedIndexChanged Select Case UCase(Me.cboBLData.Text) Case "CNTR&MARKING" Dim frmCntrMark As New frmSeaCntrMarking() frmCntrMark.pHBLNo = Me.txtHBLNo.Text
0
407
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 corresponding field in the lookup table. In my data table we store the ID in what I will call the 'key' field. == Description of the desired operation:
4
4606
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 bound to a table as a lookup, drawing values from another table to populate the available selections. This all worked fine in VB6. I have distilled the problem down to a simple form drawing data from the Northwind database for a representative...
5
24995
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
8657
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 list of values from a table, and as the user selects values, a datagrid displays related records from another table because it is bound via FK relationship. My table: /****** Object: Table . Script Date: 06/19/2006
2
2448
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, if the value is not found, meaning is hasn't been entered, goes to record 1. I have also created a macro through the use of a command button which, if the value is not already entered, will open a new record and prepopulate the Error# field....
0
7871
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
5735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5400
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3851
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3893
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2379
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1467
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1202
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.