Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Objects and list boxes

Objects and list boxes

Scheduled Pinned Locked Moved C#
databasequestion
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Barry Lapthorn
    wrote on last edited by
    #1

    I am getting data from a database, and after some pushing and poking, I have a User object. I then create a list of these Users. I have a couple of accessors:

    public string FullName()
    {
    get
    {
    return m_name;
    }
    }

    public User GetUser()
    {
    get
    {
    return this;
    }
    }

    and

    lstUsers.DisplayMember = "FullName";
    lstUsers.ValueMember = "GetUser";

    and finally

    private void lstUsers_SelectedIndexChanged(...)
    {
    User u = (User)(lstUsers.SelectedValue);
    ...
    }

    There must be an easy way than this. Any ideas? Regards, Barry

    L D 2 Replies Last reply
    0
    • B Barry Lapthorn

      I am getting data from a database, and after some pushing and poking, I have a User object. I then create a list of these Users. I have a couple of accessors:

      public string FullName()
      {
      get
      {
      return m_name;
      }
      }

      public User GetUser()
      {
      get
      {
      return this;
      }
      }

      and

      lstUsers.DisplayMember = "FullName";
      lstUsers.ValueMember = "GetUser";

      and finally

      private void lstUsers_SelectedIndexChanged(...)
      {
      User u = (User)(lstUsers.SelectedValue);
      ...
      }

      There must be an easy way than this. Any ideas? Regards, Barry

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Barry Lapthorn wrote: There must be an easy way than this. Any ideas? Looks easy enough for me! top secret xacc-ide 0.0.1

      B 1 Reply Last reply
      0
      • L leppie

        Barry Lapthorn wrote: There must be an easy way than this. Any ideas? Looks easy enough for me! top secret xacc-ide 0.0.1

        B Offline
        B Offline
        Barry Lapthorn
        wrote on last edited by
        #3

        I should have said 'less crap' ;) The 'callback' is a string. Seems to me like it would be boiler plate code (returning an object handle from a selected list) and perhaps should have been in the CLR. Regards, Barry

        1 Reply Last reply
        0
        • B Barry Lapthorn

          I am getting data from a database, and after some pushing and poking, I have a User object. I then create a list of these Users. I have a couple of accessors:

          public string FullName()
          {
          get
          {
          return m_name;
          }
          }

          public User GetUser()
          {
          get
          {
          return this;
          }
          }

          and

          lstUsers.DisplayMember = "FullName";
          lstUsers.ValueMember = "GetUser";

          and finally

          private void lstUsers_SelectedIndexChanged(...)
          {
          User u = (User)(lstUsers.SelectedValue);
          ...
          }

          There must be an easy way than this. Any ideas? Regards, Barry

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Barry Lapthorn wrote: There must be an easy way than this. Any ideas? To do what? You really haven't said what your problem is. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          G B 2 Replies Last reply
          0
          • D Dave Kreskowiak

            Barry Lapthorn wrote: There must be an easy way than this. Any ideas? To do what? You really haven't said what your problem is. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

            G Offline
            G Offline
            gantww
            wrote on last edited by
            #5

            You could also override the ToString() method of your object and make it return the username as a string. As far as the callback goes, why not just insert the object into the listbox. When you want to get it back out, all you need to do is cast it to the appropriate type. Or am I missing something? Will

            B 1 Reply Last reply
            0
            • D Dave Kreskowiak

              Barry Lapthorn wrote: There must be an easy way than this. Any ideas? To do what? You really haven't said what your problem is. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

              B Offline
              B Offline
              Barry Lapthorn
              wrote on last edited by
              #6

              My problem is that return the reference to the object from a drop down list must be a common thing, and there's no consistent (e.g. interface) way of doing it, and that the way you have to do it is via a function call back that is a string, and therefore weakly typed. Regards, Barry

              1 Reply Last reply
              0
              • G gantww

                You could also override the ToString() method of your object and make it return the username as a string. As far as the callback goes, why not just insert the object into the listbox. When you want to get it back out, all you need to do is cast it to the appropriate type. Or am I missing something? Will

                B Offline
                B Offline
                Barry Lapthorn
                wrote on last edited by
                #7

                Do you have an example of this? :) Regards, Barry

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups