Solved

vb.net - Adding Item To Combo box collection

Posted on 2007-04-06
3
455 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 250 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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

627 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