newbie: replace with default text when cmbbox entry is empty

S

steve

hi,
I was wondering if there is any way around the following:

I am populating two (synchronized) comboboxes from database fields. The first box is binded to a primary key and therefore is never empty, however the second can be empty depending on the first one's value:

cmb1 cmb2
---------------------------
112 hello
221 mary
334 (null)
443 (null)
111 john

Is there any way to detect and *replace* with another string the null values ?

I tried this:

Private Sub cmb2_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmb2.TextChanged
If cmb2.Text = "" Then
cmb2.Text="-?-"
End If
End Sub

but it raises an exception !!!!?????

What I would like to have ideally is the second list being populated only with non-null values. but if the user scrolled on the first list he would be able to see all values and the null ones on the second list would be replaced by some text (like: -?-).
Is this possible?

Thanx in advance!

-steve
 
O

One Handed Man \( OHM - Terry Burns \)

Is this two tables which are arelated. Such as Order/Order Details, if so why do you have Null values on the relation ?.

The idea with binding is that the data reflects that to which it is bound. Can you be more specific about the way this is all configured.

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--


hi,
I was wondering if there is any way around the following:

I am populating two (synchronized) comboboxes from database fields. The first box is binded to a primary key and therefore is never empty, however the second can be empty depending on the first one's value:

cmb1 cmb2
---------------------------
112 hello
221 mary
334 (null)
443 (null)
111 john

Is there any way to detect and *replace* with another string the null values ?

I tried this:

Private Sub cmb2_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmb2.TextChanged
If cmb2.Text = "" Then
cmb2.Text="-?-"
End If
End Sub

but it raises an exception !!!!?????

What I would like to have ideally is the second list being populated only with non-null values. but if the user scrolled on the first list he would be able to see all values and the null ones on the second list would be replaced by some text (like: -?-).
Is this possible?

Thanx in advance!

-steve
 
S

steve

Hmmm.... I definetely don't know much about databases but I would think that this is OK... (?)
An example would be the following:
tblCustomers has CustomerID as the key
tblCustomerInfo has CustomerID as the foreign key.

Therefore the two tables are related (dataset.relation in my code btw).
Now I populate the first field with CustomerID the second with CustomerName etc... so that since the combos are synchronized, the user can scroll and select either by ID or Name, etc. and all of them will updated.
One of the comboboxes though is bound to CustomerHeight, which we may NOT have this information for all customers. I think this is reasonable.

So, when i scroll in the CustomerHeight combo there are a lot of "gaps" simply because there are no values there.

I know i could go back to the database and replace all null values with a default string, but is there a way to get around it the way it is ? I simply want to replace an empty string with a default one, but as i said, when i use the cmb2_TextChanged( ) method it raises an exception.

And, again, what would be Really nice is to be able to "shrink" the CustomerHeight combo to only non-empty values, but ONLY when the user scrolls that one! I obviously dont want to loose the info from the other comboboxes that contain other fields.

In other words, in my original example, the user would see:

112
221
334
443
111

in the first box, but the second would be:

hello
mary
john

(we removed the empty ones )

Hope now it is clear.

Thanx again for your effort!


"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> a écrit dans le message de Is this two tables which are arelated. Such as Order/Order Details, if so why do you have Null values on the relation ?.

The idea with binding is that the data reflects that to which it is bound. Can you be more specific about the way this is all configured.

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--


hi,
I was wondering if there is any way around the following:

I am populating two (synchronized) comboboxes from database fields. The first box is binded to a primary key and therefore is never empty, however the second can be empty depending on the first one's value:

cmb1 cmb2
---------------------------
112 hello
221 mary
334 (null)
443 (null)
111 john

Is there any way to detect and *replace* with another string the null values ?

I tried this:

Private Sub cmb2_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmb2.TextChanged
If cmb2.Text = "" Then
cmb2.Text="-?-"
End If
End Sub

but it raises an exception !!!!?????

What I would like to have ideally is the second list being populated only with non-null values. but if the user scrolled on the first list he would be able to see all values and the null ones on the second list would be replaced by some text (like: -?-).
Is this possible?

Thanx in advance!

-steve
 
O

One Handed Man \( OHM - Terry Burns \)

OK, now I understand what you have done that makes it all the more clear. I dont think this is possible, because what you have done is to bind the record(s) to your second ComboBox, so you are viewing a particular field ( which happens to have Null values in some rows ). It would be better to ensure that the object to which the second combo box only has rows available which do ( Not ) have the Null value.

Can you not use a filter on the table so that the default view only presents records based on your selected value in combo box1.

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--


Hmmm.... I definetely don't know much about databases but I would think that this is OK... (?)
An example would be the following:
tblCustomers has CustomerID as the key
tblCustomerInfo has CustomerID as the foreign key.

Therefore the two tables are related (dataset.relation in my code btw).
Now I populate the first field with CustomerID the second with CustomerName etc... so that since the combos are synchronized, the user can scroll and select either by ID or Name, etc. and all of them will updated.
One of the comboboxes though is bound to CustomerHeight, which we may NOT have this information for all customers. I think this is reasonable.

So, when i scroll in the CustomerHeight combo there are a lot of "gaps" simply because there are no values there.

I know i could go back to the database and replace all null values with a default string, but is there a way to get around it the way it is ? I simply want to replace an empty string with a default one, but as i said, when i use the cmb2_TextChanged( ) method it raises an exception.

And, again, what would be Really nice is to be able to "shrink" the CustomerHeight combo to only non-empty values, but ONLY when the user scrolls that one! I obviously dont want to loose the info from the other comboboxes that contain other fields.

In other words, in my original example, the user would see:

112
221
334
443
111

in the first box, but the second would be:

hello
mary
john

(we removed the empty ones )

Hope now it is clear.

Thanx again for your effort!


"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> a écrit dans le message de Is this two tables which are arelated. Such as Order/Order Details, if so why do you have Null values on the relation ?.

The idea with binding is that the data reflects that to which it is bound. Can you be more specific about the way this is all configured.

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--


hi,
I was wondering if there is any way around the following:

I am populating two (synchronized) comboboxes from database fields. The first box is binded to a primary key and therefore is never empty, however the second can be empty depending on the first one's value:

cmb1 cmb2
---------------------------
112 hello
221 mary
334 (null)
443 (null)
111 john

Is there any way to detect and *replace* with another string the null values ?

I tried this:

Private Sub cmb2_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmb2.TextChanged
If cmb2.Text = "" Then
cmb2.Text="-?-"
End If
End Sub

but it raises an exception !!!!?????

What I would like to have ideally is the second list being populated only with non-null values. but if the user scrolled on the first list he would be able to see all values and the null ones on the second list would be replaced by some text (like: -?-).
Is this possible?

Thanx in advance!

-steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top