?
Solved

Formatting Data Bound ComboBox

Posted on 2013-06-06
6
Medium Priority
?
477 Views
Last Modified: 2013-06-11
I have a ComboBox which displays a list of COM ports to chose from:
COM1
COM2
COM3
COM4
COM5

The underlying data source it's bound to just stores an integer {1,2,3,4,5} instead of a string.

So how do I get the ComboBox to display "COM" + i ?

And in reverse, when the user changes the ComboBox, I just want to store the integer (possibly the (SelectedIndex + 1).

And it's all done with Data Binding. I have a:

MyDataSet1
MyBindingSource
MyTableAdapter
TableAdapterManager

which Visual Studio kindly added for me. (All I did was drag from my Data Source to my form.)

I was looking for a Parse event but didn't find it, or I'm not looking in the right place. Or I'm looking for a Format event, or I need an IFormatProvider. What I really need is a working example, since one working example is worth a book full of wordy explanations.

Thought I saw an article on CodeProject explaining how to do this but I've given up trying to find it again.
0
Comment
Question by:deleyd
[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
6 Comments
 
LVL 58

Expert Comment

by:Julian Hansen
ID: 39227337
Can you post code of where you are so far?
0
 
LVL 10

Assisted Solution

by:adriankohws
adriankohws earned 1600 total points
ID: 39229178
If you need to use binding, then play with:
ValueMember and DisplayMember

ValueMember for you to keep Index and DisplayMember is the text going to be displayed.

Usually I don't use bindings. I will always keep relating list in Arraylists.

---------------------------------------------------------------------------------------------------------

Create a combobox named "cbTest" on a new form and paste these codes to see.

    Dim a As New ArrayList
    Dim b As New ArrayList


    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        LoadArrayList()
        LoadCB()
    End Sub

    Private Sub LoadArrayList()
        Dim x As Integer
        For x = 1 To 5
            a.Add(x)
        Next
        For x = 1 To 5
            b.Add("COM " + CStr(x))
        Next
    End Sub

    Sub LoadCB()
        Dim x As Integer
        For x = 1 To a.Count
            cbTest.Items.Add(b(x - 1))
        Next
    End Sub

    Private Sub cbTest_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbTest.SelectedIndexChanged
        MsgBox(a(cbTest.SelectedIndex))
    End Sub
0
 

Author Comment

by:deleyd
ID: 39230364
Hmm still not quite what I was looking for. There's some way to format data bound stuff, an event or something to intercept where you can then fiddle with what actually gets displayed. Some doc I have says look into a Parse event and a Format event.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 10

Accepted Solution

by:
adriankohws earned 1600 total points
ID: 39231024
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 400 total points
ID: 39239029
0
 

Author Closing Comment

by:deleyd
ID: 39239748
I ended up doing it just manually. The FORMAT and PARSE events I was looking for is for the older "Binding" whereas nowadays we use "BindingSource" which apparently doesn't have those options.''

I do see the FORMAT event for ListControl, which ComboBox does have, though I'm not quite clear what one can do during the FORMAT event.

Thank you everyone.
0

Featured Post

PowerShell Core for Advanced Linux Administrators

Understand advanced principals around Powershell Core with a focus on the Linux Administrator.  This course covers how to administer numerous environments across multiple platforms including Linux, Azure, AWS, and Google Cloud from a single shell instance.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

718 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