Assigning datasource to combo box

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

    Assigning datasource to combo box

    Hi

    I am using below code to fill the drop down list of a combo box from a table
    in the dataset;

    Dim dv As New DataView(ds.Com panies)
    Me.txtParent.Da taSource = dv
    Me.txtParent.Da taMember = "Company"
    dv.Dispose()
    dv = Nothing

    Unfortunately no data turns up in combo box. What am I doing wrong?

    Thanks

    Regards


  • Herfried K. Wagner [MVP]

    #2
    Re: Assigning datasource to combo box

    "John" <John@nospam.in fovis.co.ukschr ieb:
    I am using below code to fill the drop down list of a combo box from a
    table in the dataset;
    >
    Dim dv As New DataView(ds.Com panies)
    Me.txtParent.Da taSource = dv
    Me.txtParent.Da taMember = "Company"
    dv.Dispose()
    dv = Nothing
    >
    Unfortunately no data turns up in combo box. What am I doing wrong?
    Remove the last two lines. You must not destroy the data source as long as
    the control depends on it. In addition, setting local variables to
    'Nothing' is (with very few exception) not the best style.

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

    Comment

    • John

      #3
      Re: Assigning datasource to combo box

      Hi

      Thanks. No luck I am afraid. I have tried all this;

      Dim dv As New DataView(ds.Cli ents)

      1. Me.txtParent.Da taSource = "dv.company "

      2. Me.txtParent.Da taSource = dv
      Me.txtParent.Da taMember = "company"

      3. Me.txtParent.Da taSource = ds.Clients
      Me.txtParent.Da taMember = "company"

      Any ideas? I have tested ds.Clients.Coun t and it returns more than zero so
      there are records in the dataset.

      Thanks

      Regards

      "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.atwrot e in message
      news:uE1qYqPbIH A.4180@TK2MSFTN GP06.phx.gbl...
      "John" <John@nospam.in fovis.co.ukschr ieb:
      >I am using below code to fill the drop down list of a combo box from a
      >table in the dataset;
      >>
      >Dim dv As New DataView(ds.Com panies)
      >Me.txtParent.D ataSource = dv
      >Me.txtParent.D ataMember = "Company"
      >dv.Dispose()
      >dv = Nothing
      >>
      >Unfortunatel y no data turns up in combo box. What am I doing wrong?
      >
      Remove the last two lines. You must not destroy the data source as long
      as the control depends on it. In addition, setting local variables to
      'Nothing' is (with very few exception) not the best style.
      >
      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

      Comment

      • Cor Ligthert[MVP]

        #4
        Re: Assigning datasource to combo box

        John,

        Are you sure you have the right control. I see seldom people call a combobox
        txt that is mostly (forever) used for a textbox.

        You have to set the displaymember in the way you did it as in 2 and 3.
        However, normally the valuemember is set as well.

        Cor

        Comment

        • RobinS

          #5
          Re: Assigning datasource to combo box

          You need to set the display member and value member. They can be the same
          thing. They must be what field in the dataset you want to use.

          Me.txtParent.Da taSource = ds.Clients
          Me.txtParent.Di splayMember = "CompanyNam e"
          Me.txtParent.Va lueMember = "CompanyID"

          RobinS.
          GoldMail, Inc.
          ------------------------------------
          "John" <John@nospam.in fovis.co.ukwrot e in message
          news:OPzCUiQbIH A.1204@TK2MSFTN GP03.phx.gbl...
          Hi
          >
          Thanks. No luck I am afraid. I have tried all this;
          >
          Dim dv As New DataView(ds.Cli ents)
          >
          1. Me.txtParent.Da taSource = "dv.company "
          >
          2. Me.txtParent.Da taSource = dv
          Me.txtParent.Da taMember = "company"
          >
          3. Me.txtParent.Da taSource = ds.Clients
          Me.txtParent.Da taMember = "company"
          >
          Any ideas? I have tested ds.Clients.Coun t and it returns more than zero so
          there are records in the dataset.
          >
          Thanks
          >
          Regards
          >
          "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.atwrot e in message
          news:uE1qYqPbIH A.4180@TK2MSFTN GP06.phx.gbl...
          >"John" <John@nospam.in fovis.co.ukschr ieb:
          >>I am using below code to fill the drop down list of a combo box from a
          >>table in the dataset;
          >>>
          >>Dim dv As New DataView(ds.Com panies)
          >>Me.txtParent. DataSource = dv
          >>Me.txtParent. DataMember = "Company"
          >>dv.Dispose( )
          >>dv = Nothing
          >>>
          >>Unfortunate ly no data turns up in combo box. What am I doing wrong?
          >>
          >Remove the last two lines. You must not destroy the data source as long
          >as the control depends on it. In addition, setting local variables to
          >'Nothing' is (with very few exception) not the best style.
          >>
          >--
          >M S Herfried K. Wagner
          >M V P <URL:http://dotnet.mvps.org/>
          >V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
          >
          >

          Comment

          • Martin M

            #6
            Re: Assigning datasource to combo box

            Could try DaisyCombo released by www.springsys.com.


            -martin
            Hi
            >
            I am using below code to fill the drop down list of a combo box from a
            table in the dataset;
            >
            Dim dv As New DataView(ds.Com panies)
            Me.txtParent.Da taSource = dv
            Me.txtParent.Da taMember = "Company"
            dv.Dispose()
            dv = Nothing
            >
            Unfortunately no data turns up in combo box. What am I doing wrong?
            >
            Thanks
            >
            Regards
            >

            Comment

            Working...