Solved

Formatting Data Bound ComboBox

Posted on 2013-06-06
6
476 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 400 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 10

Accepted Solution

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

Assisted Solution

by:CodeCruiser
CodeCruiser earned 100 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

636 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