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. checking items in a ListView

checking items in a ListView

Scheduled Pinned Locked Moved C#
helptutorial
3 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.
  • U Offline
    U Offline
    User 508833
    wrote on last edited by
    #1

    i'm having a problem when i check some items in a listview. i have a textbox and a listview and when i check the items in the listview it updates the text in the textbox. my problem is when i check the items my event is always one step behind. example, i check 'a' and nothing happens, i check 'b' and the textbox show 'a', i check 'c' and the textbox shows 'a, b'. what event do i put my code into or is there a trick to this. thanks, Rob my event: private void lvNameDisplay_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e) { // System.Text.StringBuilder newText = new System.Text.StringBuilder(); foreach (ListViewItem lvItem in lvNameDisplay.CheckedItems) { // newText.Append(lvItem.Text + ", "); } tbExample.Text = newText.ToString(); if (tbExample.Text.EndsWith(", ")) { tbExample.Text = tbExample.Text.Substring(0, tbExample.Text.Length-2); } } -- There are 10 kinds of people. Those who understand binary and those who don't.

    Z 1 Reply Last reply
    0
    • U User 508833

      i'm having a problem when i check some items in a listview. i have a textbox and a listview and when i check the items in the listview it updates the text in the textbox. my problem is when i check the items my event is always one step behind. example, i check 'a' and nothing happens, i check 'b' and the textbox show 'a', i check 'c' and the textbox shows 'a, b'. what event do i put my code into or is there a trick to this. thanks, Rob my event: private void lvNameDisplay_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e) { // System.Text.StringBuilder newText = new System.Text.StringBuilder(); foreach (ListViewItem lvItem in lvNameDisplay.CheckedItems) { // newText.Append(lvItem.Text + ", "); } tbExample.Text = newText.ToString(); if (tbExample.Text.EndsWith(", ")) { tbExample.Text = tbExample.Text.Substring(0, tbExample.Text.Length-2); } } -- There are 10 kinds of people. Those who understand binary and those who don't.

      Z Offline
      Z Offline
      ZippyBubbleHead
      wrote on last edited by
      #2

      Try writing ur code in the handler for SelectedValueChanged event. The ItemCheck event is triggered just BEFORE an item is about to be checked...and the value is updated only AFTER this event completes...that explains the "lag" u xperienced! private void listview_SelectedValueChanged(object sender, System.EventArgs e) { System.Text.StringBuilder newText = new System.Text.StringBuilder(); System.Windows.Forms.CheckedListBox.CheckedItemCollection col = clv.CheckedItems; foreach (Object obj in col) { // newText.Append(obj.ToString() + ", "); } t1.Text = newText.ToString(); if (t1.Text.EndsWith(", ")) { t1.Text = t1.Text.Substring(0, t1.Text.Length-2); } } Zippy

      U 1 Reply Last reply
      0
      • Z ZippyBubbleHead

        Try writing ur code in the handler for SelectedValueChanged event. The ItemCheck event is triggered just BEFORE an item is about to be checked...and the value is updated only AFTER this event completes...that explains the "lag" u xperienced! private void listview_SelectedValueChanged(object sender, System.EventArgs e) { System.Text.StringBuilder newText = new System.Text.StringBuilder(); System.Windows.Forms.CheckedListBox.CheckedItemCollection col = clv.CheckedItems; foreach (Object obj in col) { // newText.Append(obj.ToString() + ", "); } t1.Text = newText.ToString(); if (t1.Text.EndsWith(", ")) { t1.Text = t1.Text.Substring(0, t1.Text.Length-2); } } Zippy

        U Offline
        U Offline
        User 508833
        wrote on last edited by
        #3

        thank you for the help but i'm using a listView not a listBox. the listView doesn't have an event for selectedvaluechanged. thanks, Rob -- There are 10 kinds of people. Those who understand binary and those who don't.

        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