Chris W

Chris W

  • NA
  • 4
  • 4.1k

Change text to edit in BeforeLabelEdit( ) event?

Mar 16 2006 2:55 PM
Does anyone know if it is possible in a ListView BeforeLabelEdit event to change the text that user is going to edit, just before the edit? 

Here's my code.  None of the items below (remmed out) work to change the text the user is going to edit.  Any ideas are greatly appreciated!!

private void listView1_BeforeLabelEdit(object sender, System.Windows.Forms.LabelEditEventArgs e){
    // Remove "(default)" from the template name
   string name = this
.listView1.SelectedItems[0].Text;
   if
(name.IndexOf(" (default)") >= 0)
   {
       // Remove the word
       name = name.Substring(0, name.Length - 10);

       // NONE OF THESE THINGS WORK TO FORCE USER TO MODIFY THE NEW TEXT!
       //e.Label = name; // READ-ONLY!
       //this.listView1.Items[e.Item].Text = name; // REMOVES (default) AFTER EDIT!

       //this
.listView1.SelectedItems[0].Text = name; // REMOVES (default) AFTER EDIT!
       
       // Cancel event and refire it?
       //e.CancelEdit = true; //DOES NOT WORK!
       //listView1_BeforeLabelEdit(sender, e); //DOES NOT WORK!

    }
}


Answers (1)