Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

vb 2010 sorting combo box with data source

Posted on 2014-01-21
6
Medium Priority
?
433 Views
Last Modified: 2014-02-01
I have a combo box that has a data source as a one dimensional array because I am using Retrieve list to get data from an as400 file.  I need to add an item so I converted it to a list. Now I need to add that item at the beginning or reverse the list. I am able to accomplish the above but when I insert, sort or reverse the list the combo box will display the member and value instead of just the Display member. If I take the insert, sort or reverse out it will go back to just displaying the member. If I use the add method on the list it just populates the list at the end, as expected. But with the add display member is the only thing that appears in the combo box.  I have added an image below for a better understanding.


Dim location As String = "I"
            Dim columns = M_METPCols.M_ETDS + M_METPCols.M_ETCD

            'populate combo box in datagridview
            Dim cboDescription As New DataGridViewComboBoxColumn
            CBDescription.Tag = M_METPCols.M_ETDS
            Dim Desc = TroubleContext.M_METP.RetrieveList(columns, M_METPExprs.M_EARL = "I")
         *******   below is were I am trying to sort ********************
            Dim genericList As New List(Of Object)
            genericList.AddRange(Desc)

            genericList.Add("Start Here")
            genericList.Reverse()

            CBDescription.DisplayMember = "M_ETDS"
            CBDescription.ValueMember = "M_ETCD"

            CBDescription.DataSource = genericList



            'Retrieve line number with signon name
            MstLine = New DataContext(True)
            Dim LineNumber = MstLine.M_MSTLIN.RetrieveItem(M_MSTLINCols.M_EMWC, M_MSTLINExprs.USER = cf.UserName)


            'populate item combo box with the engine component issue
            BOM = New DataContext(True)
            BOM.Connect(cf.Server, cf.PortNumber, cf.Partition, cf.UserName, cf.Password)
            Dim BOMList = BOM.M_MIIP.RetrieveList(M_MIIPExprs.M_EMWC = LineNumber.ToString)

            Dim DESCS
            For a = 0 To BOMList.Count - 1
                DESCS = BOMList(a).IMSD10
                CBITEM.Items.Add(DESCS)
            Next

        End If
    End Sub
Capture.PNG
0
Comment
Question by:MVLIS
  • 4
  • 2
6 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39806243
Can you show a screenshot with the combobox open? For both cases please.
0
 

Author Comment

by:MVLIS
ID: 39807270
Thank you so much, screen shots are below.
screen.jpg
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39807583
What happens if you change

            genericList.AddRange(Desc)

            genericList.Add("Start Here")
            genericList.Reverse()

to

            genericList.Add("Start Here")
            genericList.AddRange(Desc)
?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:MVLIS
ID: 39807730
Same issue, but I think something like
genericList.add(new OBJECT{M_ETDS=""Start Here"", M_ETCD=""5""})  needs to happen.

not sure what the OBJECT is though, I tried New genericList but doesn't work.
0
 

Accepted Solution

by:
MVLIS earned 0 total points
ID: 39812397
After several hours finally got it.



'populate combo box in datagridview
            Dim cboDescription As New DataGridViewComboBoxColumn
            CBDescription.Tag = M_METPCols.M_ETDS
            Dim Desc = TroubleContext.M_METP.RetrieveList(columns, M_METPExprs.M_EARL = "I")
            Dim genericList As New List(Of Object)
            genericList.AddRange(Desc)

            genericList.Add(New M_METP())
            Dim c = genericList.Count()
            genericList.Insert(genericList.Count() - 1, New M_METP() With {.M_ETDS = "insert here", .M_ETCD = 5})
            genericList.Reverse()

            CBDescription.DisplayMember = "M_ETDS"
            CBDescription.ValueMember = "M_ETCD"

            CBDescription.DataSource = genericList
0
 

Author Closing Comment

by:MVLIS
ID: 39826092
Thank you for replying back but I was finally able to solve on my own.
0

Featured Post

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.

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
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

783 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