Solved

Format Text In Control From Binding Source

Posted on 2008-10-11
1
228 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
1 Comment
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

789 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