Hidden data in ListBox/ListView items?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • markliam@gmail.com

    #1

    Hidden data in ListBox/ListView items?

    I have a ListBox that is displaying a formatted string based on the
    contents of a DataSet. The purpose of the listbox is for the user to
    select an entry to delete, but I'm not sure how to match the listbox
    entry with the corresponding DataRow.

    The DataRow contains a unique id, but the id is not displayed in the
    formatted string that appears in the listbox. Is there a way to
    associate the id of the DataRow with the Listbox item so I know which
    DataRow id to delete based on which listbox item is selected?

  • Stephany Young

    #2
    Re: Hidden data in ListBox/ListView items?

    Simply add another column to the ListView, set it's Visible property to
    False and insert the unique id from the DataRow in that column.

    When the user selects a row in the ListView, parse the content of the hidden
    column and voila.


    <markliam@gmail .comwrote in message
    news:08cfba42-60bb-4776-a4c6-fcecc3d0e3cf@w4 0g2000hsb.googl egroups.com...
    >I have a ListBox that is displaying a formatted string based on the
    contents of a DataSet. The purpose of the listbox is for the user to
    select an entry to delete, but I'm not sure how to match the listbox
    entry with the corresponding DataRow.
    >
    The DataRow contains a unique id, but the id is not displayed in the
    formatted string that appears in the listbox. Is there a way to
    associate the id of the DataRow with the Listbox item so I know which
    DataRow id to delete based on which listbox item is selected?
    >

    Comment

    • Nicholas Paldino [.NET/C# MVP]

      #3
      Re: Hidden data in ListBox/ListView items?

      I think a better idea is to set the Tag property on the ListViewItem to
      the id of the corresponding DataRow. This way, you don't have to deal with
      extra columns, etc, etc.


      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m

      "Stephany Young" <noone@localhos twrote in message
      news:esi$0hwLIH A.1204@TK2MSFTN GP03.phx.gbl...
      Simply add another column to the ListView, set it's Visible property to
      False and insert the unique id from the DataRow in that column.
      >
      When the user selects a row in the ListView, parse the content of the
      hidden column and voila.
      >
      >
      <markliam@gmail .comwrote in message
      news:08cfba42-60bb-4776-a4c6-fcecc3d0e3cf@w4 0g2000hsb.googl egroups.com...
      >>I have a ListBox that is displaying a formatted string based on the
      >contents of a DataSet. The purpose of the listbox is for the user to
      >select an entry to delete, but I'm not sure how to match the listbox
      >entry with the corresponding DataRow.
      >>
      >The DataRow contains a unique id, but the id is not displayed in the
      >formatted string that appears in the listbox. Is there a way to
      >associate the id of the DataRow with the Listbox item so I know which
      >DataRow id to delete based on which listbox item is selected?
      >>
      >

      Comment

      Working...