CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2008
    Posts
    42

    populating dropdown in windows forms

    i have a form with a dropdown
    i am populating dropdowmn from database but having few issues

    i have a sub function fr populating the dropdown as
    Dim da1 As New SqlDataAdapter(cmd1)
    Dim ds1 As New DataSet()
    da1.Fill(ds1, "M_customer")
    Me.drpcust.DataSource = ds1

    Me.drpcust.DisplayMember = "Cname"
    Me.drpcust.ValueMember = "CID"

    but after this line Me.drpcust.DataSource = ds1 the prg flow jumps to another sub function
    having If drpcust.SelectedIndex = -1 Then

    cmdsave.Enabled = False
    Button1.Enabled = False
    which shld not happen
    and even he dropdown is not getting populated

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: populating dropdown in windows forms

    You message is not very clear, If what you are saying is that you are calling another sub routine which checks the selectedindex before you have even assigned the members of the list then it would be = -1 as nothign would be selected nor would I expect anything to be in the list.

    Show the code including the sub routine call and the code of the sub routine and use code tags with proper indenting so as to make it easy to read.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: populating dropdown in windows forms

    this code ....
    Code:
    Me.drpcust.DataSource = ds1
    will ALWAYS trigger the drpcust.SelectedIndexChanged event, because the list is been changed, and thus the index has changed too...

    If you do not want this action then you have to add a Bool to check and skip if your Binding the data source..

    The reason your probably getting nothing in the DDL is there is a Problem with your Data.. check the da1.Count value for how many items are in the dataset...
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured