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