Solved

Format Text In Control From Binding Source

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 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

21 Experts available now in Live!

Get 1:1 Help Now