Resolved ListBox whose items can be edited / discarded /accepted

mauede

Well-known member
Joined
Sep 1, 2021
Messages
103
Location
Northwood - UK
Programming Experience
Beginner
I would appreciate some help in implementing the following with WPF.
I need to have a ListBox displaying a list of strings but some may be empty strings.
Each ListBox item can be edited, discarded, or accepted.
Therefore, besides the editable ListBox I need some other type of WPF control that qualifies the status
of each item (string): "Edit / Discard / Accept" decided by the user.
I thought to use a Radio-Button for each ListBox but this type of control provides only two possible states.
If the ListBox items are editable, then I need only two states' control on each item: Discard / Accept.
Furthermore, all the ListBox items (strings) and their status must be available to the code behind when the user
clicks on a Button "Confirm". Only the strings that have "Accept" status, and are not empty, will be recorded to a database.

Many thanks in advance for your help
 
I think it is better if I show also the C# code related to the editable ListBox:
C#:
        public interface INotifyPropertyChanged { }

        public class StringContainer : INotifyPropertyChanged
        {
            private string _value;
            public event PropertyChangedEventHandler PropertyChanged;
            public string Value
            {
                get { return _value; }
                set
                {
                    if (_value == value)                    // CHECK IF VALUE CHANGED
                        return;                                    // DO NOTHING
                    _value = value;                          // CHANGE VALUE
                    OnPropertyChanged("Value");    // PASS CHANGED CONTENT
                }
            }

            private void OnPropertyChanged(string propertyname)
            {
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyname));
            }
        }


Declaration of the list of strings that have to be displayed inside the editable ListBox:
ObservableCollection<StringContainer> _renamedStructNames = new ObservableCollection<StringContainer>();
        public ObservableCollection<StringContainer> RenamedStructNames
        {
            get
            {
                if (_renamedStructNames == null)
                {
                    _renamedStructNames = new ObservableCollection<StringContainer>();
                }
                return _renamedStructNames;
            }
            set
            {
                _renamedStructNames = value;
            }
        }

My method that tries to match the trail named from an external databese to the patiet RT structure names by using the Dice coefficient:
 /*-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
        /*-------------------------------------------------- AUTOMATICALLY RENAME STRUCTURES -----------------------------------------------------------------------*/
        // Duplicate structure set and rename structures ...........................................................................................................................................
        // Try to find a matching protocol structure for not-found Velocity structures through String-Matching-Algorithms ............................................         

        public ObservableCollection<StringContainer> StructuresAutomaticRename(List<string> protNames)
        {
            for (int k = 0; k < strucNames.Count; k++)
            {
                if (protNames.Contains(strucNames[k]))
                {
                    RenamedStructNames.Add(strucNames[k]);
                }
                else
                {
                    string DiceGuess = "";
                    double diceCoef = DiceCoeff(strucNames[k], protNames, ref DiceGuess);
                    RenamedStructNames.Add(strucNames[k]);
                }     
            }
            return RenamedStructNames;
        }

The compiler does not like the "Add" method with an ObservableCollection. This is the data type I have to use to implement an editable ListBox. TRUE/FALSE?
My code compares each patient's structure name with the gold-standard structure names fetched from an external database. It tries to guess change and then adds the suggested name to a list that has to be displayed and edited by the user.
How can I add a string to an ObservableCollection?

Thank you so much
 

Latest posts

Back
Top Bottom