简体   繁体   中英

Possible noob issue about radio buttons and xml in c#

Hello I'm currently self teaching C# and have run into a bit of a wall.

EDIT:I am doing Using a Windows Form application.

The program I'm currently working on can open existing .XML files for editing or create a new one. What I am tying to do is allow the user to click the radio buttons on the left that will auto populate the lines of code on the right which in tern at the end will be able to be exported.

The question is how would I bind a section of code to to a radio button so that when the radio button is selected it will add the code to the Richtextbox1 on the right?

For example I have three radio buttons in a row such as -all - none -one . and when all is selected it will write the code I linked to the radio button starting at line 17 to however long it is, and when I select None it will remove that code from those lines (mainly for cases that the user starts playing with button).

Thank you ahead of time for any help, I do apologize also because I feel this might be an easy issue I may just not be wording my searches correctly. I've finished most the program so far from the help of google but this has me stumped. Thank you again for your time.

i would bind the IsChecked property of the CheckBoxes to a enum property in your viewmodel. If your enum property changed, you edit the source property for your richtextbox and call a PropertyChanged for it.

    private RadioButtonEnum _radioButtonEnum
    public RadioButtonEnum RadioButtonEnum
    {
        get { return _radioButtonEnum; }
        set
        {
            _radioButtonEnum = value;
            OnPropertyChanged("RadioButtonEnum");
            RefreshText();
        }
    }

    private void RefreshText()
    {
        switch (RadioButtonEnum)
        {
            case None:
                //Do your changes to your TextProperty
                break;
            case All:
                //Do your changes to your TextProperty
                break;
            case One:
                //Do your changes to your TextProperty
        }
        OnPropertyChanged("YourTextProperty");
    }

Assuming you have the radio buttons in a panel and behaving properly, when you click one the other changes, you can double click each one and it will generate a CheckChanged event. This will be called when this radio button is changed (selected I think.)

For extra info, in Visual Studio, in the Design view, click on a radio button. Now look at the properties window, click the lightning bolt, this will show you all the events that this can trigger. In your case, you should work with CheckedChanged.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM