CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: ComboBox

  1. #1
    Join Date
    Apr 2008
    Location
    United States Of America
    Posts
    21

    Cool ComboBox

    Trying to load a combobox dynamically with the following piece of code.
    count gives exact number of rows !!, but the combobox does not show anything..!!.
    Any help is greatly appreciated.

    Code:
    public void loadComboBox(OdbcConnection con)
        {
            con = getConnection();
            con.Open();
            
            string str = "select distinct mgrCode from MgrDetail";
                 
            OdbcCommand nonqueryCommand = con.CreateCommand();
            nonqueryCommand.CommandText = str;
            nonqueryCommand.CommandType = CommandType.Text;
            OdbcDataReader thisReader = nonqueryCommand.ExecuteReader();
    
            DataSet ds = new DataSet();
            DataTable dTable = new DataTable("TableA");
            dTable.Load(thisReader);
            ds.Tables.Add(dTable);
            this.ComboBox1.DataSource = ds.Tables[0];
            int count = this.ComboBox1.Items.Count; //count gives exact number of rows !!
            
            con.Close();
    
        }
    Yes, Possible!!

  2. #2
    Join Date
    Dec 2005
    Location
    Waterloo ON
    Posts
    545

    Re: ComboBox

    You need to set DisplayMember and ValueMember for ComboBox. Like:
    Code:
    ComboBox1.DisplayMember = FieldNameinDataTable;
    The difficulty is that you have no idea how difficult it is.

    .Net 3.5/VS 2008

  3. #3
    Join Date
    Apr 2008
    Location
    United States Of America
    Posts
    21

    Re: ComboBox

    That worked..
    Thanks a lot.
    Yes, Possible!!

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