Using an expression to create a calculated field

W

Woody Splawn

I am trying to understand how VS does things with regard to calculated
fields. I would like to have a name field in a txtBox on a form that
consists of the firstName and lastName fields glued together. In the
environment I am used to you would place a calculated field on the form and
call it Name. It would contain a formula like "Fname + ' '+Lname".

If I understand things correctly, VS does the same thing by use of
expressions. I discovered some code that places the glued value into a
*ListBox* on a form. But I am unable to discover how, if it is possible, to
place the glued value into just a textbox on the form. I am not sure if the
Expression ability of VS is made to work this way or not but given the code
below that works for a list box, is it possible to change it and make it
place the glued value into a Text box instead. If so what is the correct
syntax? I have the code below in a button on a form.

Dim dcName As DataColumn
dcName = New DataColumn("Name")
dcName.DataType = System.Type.GetType("System.String")
dcName.Expression = "FirstName+ ' ' + LastNamet"

Me.DsCompanys1.Tables("Companys").Columns.Add(dcName)

Me.ListBox1.DataSource = Me.DsCompanys1.Tables("Companys")
Me.ListBox1.DisplayMember = "Name"
 
S

Scot Rose [MSFT]

Do you mean bind it? This worked here...

Dim dcName As DataColumn
dcName = New DataColumn("Name")
dcName.DataType = System.Type.GetType("System.String")
dcName.Expression = "FirstName+ ' ' + LastNamet"

Me.DsCompanys1.Tables("Companys").Columns.Add(dcName)
TextBox1.DataBindings.Add("Text", DSCompanys, "Companys.Name")

Want to know more? Check out the MSDN Library at http://msdn.microsoft.com or the Microsoft Knowledge Base at http://support.microsoft.com

Scot Rose, MCSD
Microsoft Visual Basic Developer Support
Email : (e-mail address removed) <Remove word online. from address>

This posting is provided “AS IS”, with no warranties, and confers no rights.




--------------------
 

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