Solved

Format Text In Control From Binding Source

Posted on 2008-10-11
1
212 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

862 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now