winform: checking for text changed

on my form, i have a listview and a textbox above it. I have Apply, OK, Cancel buttons.

Apply button is disabled.

When user double clicks a listview item, I put that item in the textbox. Now, if user changes that textbox text, I have to enable the Apply.

So, I used "TextChanged" event. I double click a listview item, puts it in the textbox and the Apply button is enabled. BUT, I havent changed the text yet. I know why the Apply button is enabled...because the previous textbox value was blank and now it's something new.

*** But I want the Apply button to change ONLY if that text is actually changed by the can I do this??
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

JimBrandleyConnect With a Mentor Commented:
You can solve this by:
1. Create a class-level boolean member, say:
private bool JustLoaded = false;

2. In your double-click handler, before you populater textBox.Text with the new value,
JustLoaded = true;

3. In you textChanged handler,
if (JustLoaded)
   JustLoaded = false;
   // Do your textChanged processing.

gauravjoshiConnect With a Mentor Commented:
my be something like

on textchange_event()
   if (listview.selectedtext != textbox.text)
         //enable apply button


hope i have understood your problem correctly

Jaime OlivaresConnect With a Mentor Software ArchitectCommented:
You cannot know if the textchanged event is produced programatically or manually.
Simplest way is to Disable the Apply button manually after copying the text from the listview.
Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

CamilliaAuthor Commented:
let me read and will post back. Thanks.
Expert1701Connect With a Mentor Commented:
Why not set LabelEdit = true on the ListView, and then handle the AfterLabelEdit event?
CamilliaAuthor Commented:
Jim's solution worked.

All Courses

From novice to tech pro — start learning today.