Home All Groups Group Topic Archive Search About

Multiple fields in a single textbox

Author
12 May 2006 5:09 AM
spamsickle
My database stores City and State in two separate columns, but I want
to display them on my form as a single field.  Since I'm a complete VB
novice, I'm not sure how to do this.  I bind the data, and I can bring
each field into my forn as a separate textbox.  I created a third
textbox, and added code in the Form_Paint routine to concatenate the
fields:

CityStateTextBox.Text = CityTextBox.Text + ", " + StateTextBox.Text

This displayed just great, and the values were correct as I moved from
record to record with the PropertyBindingNavigator.  I thought I could
just set the CityTextBox and StateTextBox to Visible = False in the
Properties window and I'd be done, but this causes the value in my
CityStateTextBox to disappear as well.

I know there must be some way to access the data values themselves for
the current row, rather than pulling them from text boxes, but I'm not
knowledgeable enough to figure it out myself.  Any suggestions?

Author
12 May 2006 5:23 AM
Spam Catcher
spamsickle@gmail.com wrote in news:1147410591.523030.105370
@j73g2000cwa.googlegroups.com:

> I know there must be some way to access the data values themselves for
> the current row, rather than pulling them from text boxes, but I'm not
> knowledgeable enough to figure it out myself.  Any suggestions?
>
>
>

Where is your data coming from? A Dataset? If so, you can just concatenate
the data directly from your dataset.
Author
12 May 2006 6:09 AM
spamsickle
Yes, the data is coming from a dataset which is filled from an
Addresses database.  I have an AddressesDataset.xsd file in my project
which contains lines like

<Mapping SourceColumn="City" DataSetColumn="City" />
<Mapping SourceColumn="State" DataSetColumn="State" />

but I still don't know how to reference these in the Form code.  Sorry
to be so ignorant; I'm not new to coding, but I am new to VB, and
trying to learn by doing.  Thanks for your help.
Author
12 May 2006 8:07 AM
rj
i also have this problem. what u can do (which is kinda corny, but it
works) is place a panel or label over the textboxes.
if you were using the oledataadapter to make the connection you could
also edit the select statement in the properties. this will bring up a
query window simillar to Ms Access query window and you could concat
the fields directly from there..
Author
12 May 2006 1:50 PM
spamsickle
That's a great suggestion, just cover up the "source" textboxes instead
of making them invisible.  I played around with your idea, and I found
that if the "rollup" textbox is dragged onto the form after the
"source" textboxes, you can just make them all the same size and pile
them one on top of the other, and the textbox with the concatenated
data will be the one that displays.  This doesn't require a panel or a
label, just cover them up with the textbox you want to display.  The
only thing that seems to be required to make this work is dragging the
destination textbox onto the form after the source textboxes.

I don't have that oledataadapter in any form that I recognize.  It
might be under the covers somewhere, but I don't see it.  All I have is
"Me.Adapter"s in the Dataset.Designer.vb, and I don't see any select
statement for my textboxes in the Properties panel.  I still think
there must be a way to get the value of the fields directly, rather
than ferrying them through intermediate textboxes, but we seem to have
stumped the experts here.
Author
12 May 2006 2:29 PM
rj
oh yes piling them on top of 1 another is also fine.
did you code the connection?
I dont know how to do it like that. if you add an "oledbdataadapter" to
your form, you'll see it appear below the forms design.
right click it and select "configure data adapter"
follow the wizard.. you can concat that field you want in the wizards
select statement.
after that you create a dataset based on the table, and then link the
relevant textboxes in the items properties.

all the best!
Author
12 May 2006 1:44 PM
Cor Ligthert [MVP]
Spamicle.

The simplest (and best) way is creating that column while you are fetching
it using SQL.
An other method is to create an expression column.

http://www.vb-tips.com/default.aspx?ID=76a81eb8-ea2d-48f4-99c3-a3539697edbd

Dont be afraid for this sample, there is only something extra because it is
so simple.

Your expression is "FirstName + ' ' + LastName"

i hope this helps,

Cor

<spamsickle@gmail.com> schreef in bericht
Show quoteHide quote
news:1147410591.523030.105370@j73g2000cwa.googlegroups.com...
> My database stores City and State in two separate columns, but I want
> to display them on my form as a single field.  Since I'm a complete VB
> novice, I'm not sure how to do this.  I bind the data, and I can bring
> each field into my forn as a separate textbox.  I created a third
> textbox, and added code in the Form_Paint routine to concatenate the
> fields:
>
> CityStateTextBox.Text = CityTextBox.Text + ", " + StateTextBox.Text
>
> This displayed just great, and the values were correct as I moved from
> record to record with the PropertyBindingNavigator.  I thought I could
> just set the CityTextBox and StateTextBox to Visible = False in the
> Properties window and I'd be done, but this causes the value in my
> CityStateTextBox to disappear as well.
>
> I know there must be some way to access the data values themselves for
> the current row, rather than pulling them from text boxes, but I'm not
> knowledgeable enough to figure it out myself.  Any suggestions?
>
Author
12 May 2006 3:17 PM
spamsickle
Thanks, Cor and rj, your suggestions have enabled me to solve my
immediate problem and learn a little about how the data access pieces
all tie together in this development environment.  I really appreciate
it.
Author
12 May 2006 3:18 PM
spamsickle
Thanks, Cor and rj, your suggestions have enabled me to solve my
immediate problem and learn a little about how the data access pieces
all tie together in this development environment.  I really appreciate
it.