?
Solved

Format Text In Control From Binding Source

Posted on 2008-10-11
1
Medium Priority
?
246 Views
Last Modified: 2012-05-05
Hello,
I have a form with a bindingsource on it set to display the "CaseNumber" value as the text for my form.  I am wondering if there is a way to display it using a "mask."  Such as "HH00-000000.0 - Calls for Service" with the numbers being replaced with the respected numbers in the database.  So for example a value of 080000011 would be displayed as "HH08-000001.1 - Calls for Service".
0
Comment
Question by:Gunit2507
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 48

Accepted Solution

by:
jpaulino earned 2000 total points
ID: 22695513
You can use the CurrentItemChanged event of the bindingsource to format your textbox.
Here's an example that uses a datagridview and three textboxes

Public Class Form1
 
    Private WithEvents mBS As New BindingSource()
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        ' Creates a demo table
        Dim dt As New DataTable()
        dt.Columns.Add("ID", GetType(Integer)).AutoIncrement = True
        dt.Columns.Add("Item", GetType(String))
        dt.Columns.Add("Date", GetType(Date))
 
        ' Adds some rows
        For i As Integer = 0 To 19
            dt.Rows.Add(New Object() {Nothing, "Item " & i, Now.AddDays(i)})
        Next
 
        ' Binds the fields
        mBS.DataSource = dt
        Me.TextBox2.DataBindings.Add("Text", mBS, "Item", True)
        Me.TextBox3.DataBindings.Add("Text", mBS, "Date", True)
 
        ' Populates the datagridview
        Me.DataGridView1.DataSource = mBS
    End Sub
 
 
    Private Sub mBS_CurrentItemChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles mBS.CurrentItemChanged
        Dim drv As DataRowView = DirectCast(mBS.Current, DataRowView)
        Me.TextBox1.Text = Integer.Parse(drv.Row("ID")).ToString("0000")
    End Sub
 
End Class

Open in new window

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question