C# preventing combox selectionChanged event from recalling itself

HighARc

I have this event handler which I need to, under certain conditions change it's selected item in code. When I do this it will recall the handler due to being changed and re-execute. How can I prevent this?

MessageBox.Show("Must have a repair report.", "No Report");
txtLocation.SelectedItem = MAIN_BACKGROUND.UserName; //here it recalls itself as I return its value to what it was before the change
rory.ap

You could use a global boolean value to stop the event body from performing its substantive work during the "inner" event handler:

private bool _alreadyChanging = false;

private void txtLocation_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if (!_alreadyChanging)
    {
        _alreadyChanging = true;
        MessageBox.Show("Must have a repair report.", "No Report");
        txtLocation.SelectedItem = MAIN_BACKGROUND.UserName;
        _alreadyChanging = false;
    }
}

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Storyboard.Completed Event Handler Preventing Code From Executing

分類Dev

Set Pivot Selection to another in SelectionChanged event

分類Dev

Preventing double event binding in jQuery

分類Dev

Preventing GTKMM from catching exceptions

分類Dev

C#DataGridView(Winforms)でのComboxの追加

分類Dev

DataBinding WPFイメージC#ListView SelectionChanged

分類Dev

Preventing main div from scrolling underneath Header

分類Dev

Frequent GC preventing sparks from running in parallel

分類Dev

Preventing RecyclerView from consuming touch events

分類Dev

Preventing thread from duplicate processing in java

分類Dev

Preventing IE / Edge from preloading video

分類Dev

Preventing users from altering default privileges on PostgreSQL

分類Dev

Preventing discord bot from crashing (mysql)

分類Dev

preventing certain docs from being indexed in clucene

分類Dev

Preventing Firefox from hiding toolbar buttons in popups

分類Dev

scrollIntoView() preventing other listeners from triggering

分類Dev

Preventing edges from crossing nodes in pygraphviz

分類Dev

Triggering an event in c# from c++ and declaring LPCWSTR

分類Dev

Preventing Bootstrap Sticky Footer From Allowing Content To Slide Beneath

分類Dev

Preventing a Python For-loop from iterating over a single string by char

分類Dev

How to find out what's preventing a click from happening?

分類Dev

Preventing gradle-wrapper.properties from changing all the time

分類Dev

An issue with preventing users from changing specific document fields in Firestore

分類Dev

Why is Application Insights Preventing my Worker Role from Starting?

分類Dev

Preventing 1 level/value of pandas df column from being plotted

分類Dev

Preventing a new page from opening when href is clicked

分類Dev

Why is Spring SAML preventing Spring OAuth2 from working?

分類Dev

Preventing Shiny selectInput from evaluating prematurely when updating a reactive plot

分類Dev

Preventing Windows program from interpreting ^Z as end of file

Related 関連記事

  1. 1

    Storyboard.Completed Event Handler Preventing Code From Executing

  2. 2

    Set Pivot Selection to another in SelectionChanged event

  3. 3

    Preventing double event binding in jQuery

  4. 4

    Preventing GTKMM from catching exceptions

  5. 5

    C#DataGridView(Winforms)でのComboxの追加

  6. 6

    DataBinding WPFイメージC#ListView SelectionChanged

  7. 7

    Preventing main div from scrolling underneath Header

  8. 8

    Frequent GC preventing sparks from running in parallel

  9. 9

    Preventing RecyclerView from consuming touch events

  10. 10

    Preventing thread from duplicate processing in java

  11. 11

    Preventing IE / Edge from preloading video

  12. 12

    Preventing users from altering default privileges on PostgreSQL

  13. 13

    Preventing discord bot from crashing (mysql)

  14. 14

    preventing certain docs from being indexed in clucene

  15. 15

    Preventing Firefox from hiding toolbar buttons in popups

  16. 16

    scrollIntoView() preventing other listeners from triggering

  17. 17

    Preventing edges from crossing nodes in pygraphviz

  18. 18

    Triggering an event in c# from c++ and declaring LPCWSTR

  19. 19

    Preventing Bootstrap Sticky Footer From Allowing Content To Slide Beneath

  20. 20

    Preventing a Python For-loop from iterating over a single string by char

  21. 21

    How to find out what's preventing a click from happening?

  22. 22

    Preventing gradle-wrapper.properties from changing all the time

  23. 23

    An issue with preventing users from changing specific document fields in Firestore

  24. 24

    Why is Application Insights Preventing my Worker Role from Starting?

  25. 25

    Preventing 1 level/value of pandas df column from being plotted

  26. 26

    Preventing a new page from opening when href is clicked

  27. 27

    Why is Spring SAML preventing Spring OAuth2 from working?

  28. 28

    Preventing Shiny selectInput from evaluating prematurely when updating a reactive plot

  29. 29

    Preventing Windows program from interpreting ^Z as end of file

ホットタグ

アーカイブ