c# combo box populating

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JC

    #1

    c# combo box populating

    Hi all,

    I have a combobox control in a c# form. I would like to populate this
    drop down with values from a dataset- so have written a procedure to
    populate a dataset.

    Once created I am using this code to populate the combobox...

    DataSet ds = new DataSet();
    ds = im.getAllOnline ();//a function that return a dataset
    comboBox1.DataS ource = ds.Tables["IM"];
    comboBox1.Displ ayMember = "username";
    comboBox1.Value Member = "userIp";

    I have checked the dataset, and it is being populated, but for some
    reason I cannot get the combobox to work.

    I would really appreciate help with this cos its driving me nuts!!!
  • Stefan

    #2
    Re: c# combo box populating

    Hi James

    if it's a webcontrol you have to bind the data to the grid
    comboBox1.DataB ind();
    "JC" <james_crane@bt internet.com> wrote in message
    news:d73038d8.0 309240016.2d369 cdc@posting.goo gle.com...[color=blue]
    > Hi all,
    >
    > I have a combobox control in a c# form. I would like to populate this
    > drop down with values from a dataset- so have written a procedure to
    > populate a dataset.
    >
    > Once created I am using this code to populate the combobox...
    >
    > DataSet ds = new DataSet();
    > ds = im.getAllOnline ();//a function that return a dataset
    > comboBox1.DataS ource = ds.Tables["IM"];
    > comboBox1.Displ ayMember = "username";
    > comboBox1.Value Member = "userIp";
    >
    > I have checked the dataset, and it is being populated, but for some
    > reason I cannot get the combobox to work.
    >
    > I would really appreciate help with this cos its driving me nuts!!![/color]


    Comment

    • Dmitriy Lapshin [C# / .NET MVP]

      #3
      Re: c# combo box populating

      Hi,

      You should establish a binding between the combo box and the data source
      instead. Please refer to the documentation on the
      System.Windows. Forms.Binding class as well as Control.Binding s collection in
      MSDN.

      --
      Dmitriy Lapshin [C# / .NET MVP]
      X-Unity Test Studio

      Bring the power of unit testing to VS .NET IDE

      "JC" <james_crane@bt internet.com> wrote in message
      news:d73038d8.0 309240016.2d369 cdc@posting.goo gle.com...[color=blue]
      > Hi all,
      >
      > I have a combobox control in a c# form. I would like to populate this
      > drop down with values from a dataset- so have written a procedure to
      > populate a dataset.
      >
      > Once created I am using this code to populate the combobox...
      >
      > DataSet ds = new DataSet();
      > ds = im.getAllOnline ();//a function that return a dataset
      > comboBox1.DataS ource = ds.Tables["IM"];
      > comboBox1.Displ ayMember = "username";
      > comboBox1.Value Member = "userIp";
      >
      > I have checked the dataset, and it is being populated, but for some
      > reason I cannot get the combobox to work.
      >
      > I would really appreciate help with this cos its driving me nuts!!![/color]

      Comment

      • James Crane

        #4
        Re: c# combo box populating

        Thanks for replying Stefan,

        The combo box in question is on a windows form, not a web form. For some
        reason the control does not have a DataBind() option that you woudl
        expect - thats what I'm finding confusing.

        Any ideas?

        Thanks

        JC





        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        • James Crane

          #5
          Re: c# combo box populating

          Hi Dmitriy,

          Thanks for the tip I'll read the articles!

          I cant link to the datasource direct cos I'm using a seperate layer to
          grab the data, and passing it over as a dataset - so I still have a
          little problem.

          Thanks for the advice though.

          JC

          *** Sent via Developersdex http://www.developersdex.com ***
          Don't just participate in USENET...get rewarded for it!

          Comment

          • Dmitriy Lapshin [C# / .NET MVP]

            #6
            Re: c# combo box populating

            James,

            DataSets and DataTables actually are the most widely used data sources for
            the Windows Forms binding - so it's just what you need!

            --
            Dmitriy Lapshin [C# / .NET MVP]
            X-Unity Test Studio

            Bring the power of unit testing to VS .NET IDE

            "James Crane" <james_crane@bt internet.com> wrote in message
            news:O77WiMpgDH A.620@TK2MSFTNG P11.phx.gbl...[color=blue]
            > Hi Dmitriy,
            >
            > Thanks for the tip I'll read the articles!
            >
            > I cant link to the datasource direct cos I'm using a seperate layer to
            > grab the data, and passing it over as a dataset - so I still have a
            > little problem.
            >
            > Thanks for the advice though.
            >
            > JC
            >
            > *** Sent via Developersdex http://www.developersdex.com ***
            > Don't just participate in USENET...get rewarded for it![/color]

            Comment

            • James Crane

              #7
              Re: c# combo box populating


              Thanks everyone for your help - I think I've cracked it now.

              As per Miscro$t site, I went through the dataset and created an
              arrayList. I passed this to the combobox and it worked!!
              Happy days

              Thanks again

              JC


              *** Sent via Developersdex http://www.developersdex.com ***
              Don't just participate in USENET...get rewarded for it!

              Comment

              • James Crane

                #8
                Re: c# combo box populating


                Thanks everyone for your help - I think I've cracked it now.

                As per Miscro$t site, I went through the dataset and created an
                arrayList. I passed this to the combobox and it worked!!
                Happy days

                Thanks again

                JC


                *** Sent via Developersdex http://www.developersdex.com ***
                Don't just participate in USENET...get rewarded for it!

                Comment

                Working...