Multiple fields in a single textbox

G

Guest

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?
 
G

Guest

(e-mail address removed) wrote in @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.
 
G

Guest

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.
 
R

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..
 
G

Guest

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.
 
R

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!
 
G

Guest

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.
 
G

Guest

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.
 

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