Solved

Format Text In Control From Binding Source

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 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