dataset question

T

thomas1388

I am created a form to display addresses. There are 5 fields, street,
street line 2, city , state and zip code. If there is street line 2,
it will become my address line 2, City & ", " * state & zip will
become my address line 3. Since some of the addresses don't have
street line 2, I like to make City & ", " * state & zip as my address
line 2, the address line 3 will become invisible.

After I binded a dataset in the data source window, I dragged a field
into the form, the label control is data-bounced to the field. I have
tried to do the task with the following code:

If lblStreetLine2.Text = String.Empty Then
lblAddressLine2.Text = Trim(lblCity.Text) & ", " & _
Trim(lblState.Text) & " " & lblZip.Text
lblAddressLine3.Text = String.Empty
lblAddressLine3.Visible = False
Else
lblAddressLine2.Text = lblStreetLine2.Text
lblAddressLine3.Text = Trim(lblCity.Text) & ", " & _
Trim(lblState.Text) & " " & lblZip.Text
lblAddressLine3.Visible = true
End If

It didn't work. Can anyone help me? Thank you.
 
G

Guest

Well, you have me confused! When you say the labels are bound, which labels?
I am guessing that you bound the DataSource to 5 labels (invisible?) and
then are trying to display the three (different) Address labels depending on
the contents of the 5 bound labels. Am I close? While there is no reason to
do the binding to the 5 labels, I don't see why it wouldn't work. So, where
did you put the code that you showed? Sounds like it should be in your
BindingSource PositionChanged event handler. Is it?
When you say it didn't work - well can you be more specific?
 
J

Jack Jackson

I am created a form to display addresses. There are 5 fields, street,
street line 2, city , state and zip code. If there is street line 2,
it will become my address line 2, City & ", " * state & zip will
become my address line 3. Since some of the addresses don't have
street line 2, I like to make City & ", " * state & zip as my address
line 2, the address line 3 will become invisible.

After I binded a dataset in the data source window, I dragged a field
into the form, the label control is data-bounced to the field. I have
tried to do the task with the following code:

If lblStreetLine2.Text = String.Empty Then
lblAddressLine2.Text = Trim(lblCity.Text) & ", " & _
Trim(lblState.Text) & " " & lblZip.Text
lblAddressLine3.Text = String.Empty
lblAddressLine3.Visible = False
Else
lblAddressLine2.Text = lblStreetLine2.Text
lblAddressLine3.Text = Trim(lblCity.Text) & ", " & _
Trim(lblState.Text) & " " & lblZip.Text
lblAddressLine3.Visible = true
End If

It didn't work. Can anyone help me? Thank you.

It is not helpful to us to say "It didn't work".

What did it do, and how is that different from what you expected?
 
T

thomas1388

It is not helpful to us to say "It didn't work".

What did it do, and how is that different from what you expected?

In my table, there are 5 fields, street, street line 2, city, state
and zip. After I dragged those fields into the form, I named them
lblStreet, lblStreetLine2, lblCity, lblState and lblZip. The lblSteet
label control is data-bounced to the Street field, so it displays the
street of the the person selected in the list box. I could also
display street line 2 , city, state and zip the same way but I want to
do it fancier. If the street line 2 is empty, I want to make City &
", " * state & zip as my address
line 2, the address line 3 will become invisible. If street line 2 is
not null, then the address line 2 will display street line 2 and the
address line 3 will display City & ", " * state & zip. My codes are:

If lblStreetLine2.Text = String.Empty Then
lblAddressLine2.Text = Trim(lblCity.Text) & ", " & _
Trim(lblState.Text) & " " & lblZip.Text
lblAddressLine3.Text = String.Empty
Else
lblAddressLine2.Text = lblStreetLine2.Text
lblAddressLine3.Text = Trim(lblCity.Text) & ", " & _
Trim(lblState.Text) & " " & lblZip.Text
lblAddressLine3.Visible = true
End

When I run the program, the address line 2 and address line 3 return
sting empty. It doesn't matter if the street line 2 is string.empty
or not. I believe that lblCity.text, lblState.text and lblZip.text
are equal null in the program. They should not.

Please feel free to ask me if you need any additional clarification.
Thank all of you for your help.
 
G

Guest

I believe that lblCity.text, lblState.text and lblZip.text
are equal null in the program. They should not.

You don't know? Why don't you set a breakpoint and find out? If they are
all empty, then it has nothing to do with the code you included here. It is
in the binding logic somewhere. You mention a listbox, bound to a
BindingSource? Same BindingSource used by the labels? And I asked before
and will ask again, where is the code you have included? In what event
handler?
 

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