How to detect invalid character input in ListView control?
-
How to detect invalid character input in ListView control? I want to detect invalid character input while editing a ListBox's item and show a tooltip with warning. I know how to do it for TextBox control:
private void textBox1_TextChanged(object sender, EventArgs e)
{
ToolTip myTooltip = new ToolTip();
if (textBox1.Text.Contains("Invalid Character"))
{
myTooltip.Show("You entered an invalid character", textBox1);
}
}How to make it for a ListBox control? Thank you.
-
How to detect invalid character input in ListView control? I want to detect invalid character input while editing a ListBox's item and show a tooltip with warning. I know how to do it for TextBox control:
private void textBox1_TextChanged(object sender, EventArgs e)
{
ToolTip myTooltip = new ToolTip();
if (textBox1.Text.Contains("Invalid Character"))
{
myTooltip.Show("You entered an invalid character", textBox1);
}
}How to make it for a ListBox control? Thank you.
Try with ListView.BeforeLabelEdit Event. http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.beforelabeledit.aspx[^]
-
Try with ListView.BeforeLabelEdit Event. http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.beforelabeledit.aspx[^]
-
Thank you for the reply. But I can't make use of this method as I need a real-time check for user input.
You can combine two events to achieve the goal. First create a flag, like isEditing = false; On BeforeLabelEdit Event change it to true, meanwhile on AfterLabelEdit Event change it to false. Then on KeyDown Event check first if isEditing == true, then process the key. May this be the solution? EDIT: On BeforeLabelEdit Event you can store the value and on AfterLabelEdit Event get the value and see if it is changed then rise an custom event? Can this be a better way?