Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

vb.net - Adding Item To Combo box collection

Posted on 2007-04-06
3
Medium Priority
?
458 Views
Last Modified: 2008-02-01
I'm trying to add an item  ("<Select Item"> ) to a combo box in the load_gnder sub below.

I've tried "'Me.cbogender.Items.Insert(0, "<Select One>")"  which runs but wont display - and severl other ways to add the item but I cant get it to display in the combo box.


Thanks
[code]
    Private Sub load_gender()
        Dim Dsgender As New DataSet
        Dim Sqlgender As String = ("select Description,indx from gender")
        Dsgender = get_data(Sqlgender)
        Dim dvgen As DataView = Dsgender.Tables(0).DefaultView
        Me.cbogender.DataSource = dvgen
        Me.cbogender.DisplayMember = ("Description")
        Me.cbogender.ValueMember = ("indx")
    End Sub

    Public Function get_data(ByVal Sqlin As String) As DataSet
        Dim Sqldata As String = Sqlin
        Dim conn As New SqlCeConnection(connstr)
        Dim DA1 As SqlCeDataAdapter = New SqlCeDataAdapter(Sqldata, conn)
        Dim ds4 = New DataSet
        DA1.Fill(ds4, "Table1")
        conn.Dispose()
        Return ds4
    End Function

[/code]
0
Comment
Question by:gosonic
[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
3 Comments
 
LVL 21

Expert Comment

by:mastoo
ID: 18864052
You can't add items in that fashion to a databound control.  You need to "manually" populate the control and then include your extra item.
0
 
LVL 34

Accepted Solution

by:
Sancler earned 1000 total points
ID: 18867941
You could add it to the datatable itself.  Something like - in the load_gender sub

    Dim dr As DataRow = Dsgender.Tables(0).NewRow
    dr("Description") = "<Select One>"
    dr("indx") = 0
    Dsgender.Tables(0).Rows.Add(dr)

But (a) you'd then need to add a Sort to your DataView otherwise it would be the last item in the combo, when I imagine you want it to be the first and (b) it would be a New record (and so added to the database) if you did any .Update on that table.  Or why not put it in your database table?  That would deal with the issue once and for all ;-).

I assume you will have some code for checking whether a user has left it blank in any new record in which it is used, or changed to it in any existing record which s/he is editing.

Roger  
0
 

Author Comment

by:gosonic
ID: 18876388
roger

I really dont want to ad it to the DB table. You solution should work.  
Thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

670 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