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. WCF and WF
  4. Can I Do The Following With ListBox.SelectedItem?

Can I Do The Following With ListBox.SelectedItem?

Scheduled Pinned Locked Moved WCF and WF
helpquestioncareerlearning
2 Posts 2 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
    BlitzPackage
    wrote on last edited by
    #1

    Good people, I have a listbox filled with Employee objects.   Each object has employee data (e.g. name, salary, rank, birthdate, etc...). When the listbox displays, about half the time it will need to show which employee was selected on a previous screen by having that employee selected.   The listbox will contain the list of all the employees.   Of course, the data context for the listbox is AllEmployees: an observable collection of employee objects. So, can I do one or both of the following? ListBoxEmployees.SelectedItem = Employee; or ListBoxEmployees.SelectedItem = Employee as ListBoxItem; I am hoping that it will automatically find and select the appropriate employee object in its collection if I assign it the employee selected on a previous screen. Any help or information you can provide would be greatly appreciated. Thanks, Blitz

    M 1 Reply Last reply
    0
    • B BlitzPackage

      Good people, I have a listbox filled with Employee objects.   Each object has employee data (e.g. name, salary, rank, birthdate, etc...). When the listbox displays, about half the time it will need to show which employee was selected on a previous screen by having that employee selected.   The listbox will contain the list of all the employees.   Of course, the data context for the listbox is AllEmployees: an observable collection of employee objects. So, can I do one or both of the following? ListBoxEmployees.SelectedItem = Employee; or ListBoxEmployees.SelectedItem = Employee as ListBoxItem; I am hoping that it will automatically find and select the appropriate employee object in its collection if I assign it the employee selected on a previous screen. Any help or information you can provide would be greatly appreciated. Thanks, Blitz

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      BlitzPackage wrote:

      ListBoxEmployees.SelectedItem = Employee;

      Yes, assuming Employee is a reference to an employee object in the collection which is the ItemsSource for the listbox.

      BlitzPackage wrote:

      ListBoxEmployees.SelectedItem = Employee as ListBoxItem;

      No. Invalid cast there.

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      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