xceedsoftware / wpftoolkit

All the controls missing in WPF. Over 1 million downloads.
Other
3.9k stars 878 forks source link

CheckComboBox Help #1752

Open sup3r93 opened 1 year ago

sup3r93 commented 1 year ago

HI, I'm trying to use the CheckComboBox control, I take the data from an XML file, which is present in a folder on the computer, to be exact "C:\Emergency\Configuration\Configuration.xml" I used xmlDocument to import the file , and then through a foreach I added the various items, but I have two problems.

1) If I select only one item it is not shown 2) If I select two elements they are shown, but if I deselect them, the last deselected element is also shown 3) Question: How can I get the values pressed on 2 or more different strings?

Thank you so much :)

XAML CODE

<xctk:CheckComboBox Grid.Column="1" Grid.Row="4" x:Name="ComboCirculation01" Height="30" Width="200" HorizontalAlignment="Center" VerticalAlignment="Center" DisplayMemberPath="Color" ValueMemberPath="Level" SelectedValue="{Binding SelectedValue}" SelectedItemsOverride="{Binding SelectedItems}"/>

CS CODE

` #region Circulation

    public class CirculationItem {
        public string Circulation { get; set; }
        public bool IsSelected { get; set; }
    }

    private void CirculationData() {
        string configFile = @"C:\Emergenza\Configuration\Configuration.xml";

        XmlDocument xmlDocument = new XmlDocument();
        xmlDocument.Load(configFile);

        XmlNodeList nodes = xmlDocument.SelectNodes("/Config/Paziente/Associazione/Circolo/Value");

        ComboCirculation01.DisplayMemberPath = "Circulation"; 

        List<CirculationItem> circulationItems = new List<CirculationItem>();

        foreach (XmlNode node in nodes) {
            string circulation = node.InnerText;
            circulationItems.Add(new CirculationItem { Circulation = circulation });
        }

        ComboCirculation01.ItemsSource = circulationItems;
        ComboCirculation01.ItemSelectionChanged += ComboCirculation01_ItemSelectionChanged;
    }

    private void ComboCirculation01_ItemSelectionChanged(object sender, Xceed.Wpf.Toolkit.Primitives.ItemSelectionChangedEventArgs e) {
        foreach (CirculationItem item in ComboCirculation01.Items) {
            item.IsSelected = ComboCirculation01.SelectedItems.Contains(item);
        }
    }

    #endregion`

Pastebin XAML CODE Pastebin CS CODE

XceedDanP commented 1 year ago

In the xaml, you set ValueMemberPath to "Level", which is not a property on your Circulation class.

I'm not sure why it's having this weird behavior in this invalid usage, but I instead tried ValueMemberPath="Circulation" (given your example), and I then get a proper behavior.

Thanks, Dan


From: sup3r93 @.> Sent: Monday, June 5, 2023 11:52 AM To: xceedsoftware/wpftoolkit @.> Cc: Subscribed @.***> Subject: [xceedsoftware/wpftoolkit] CheckComboBox Help (Issue #1752)

HI, I'm trying to use the CheckComboBox control, I take the data from an XML file, which is present in a folder on the computer, to be exact "C:\Emergency\Configuration\Configuration.xml" I used xmlDocument to import the file , and then through a foreach I added the various items, but I have two problems.

  1. If I select only one item it is not shown
  2. If I select two elements they are shown, but if I deselect them, the last deselected element is also shown
  3. Question: How can I get the values pressed on 2 or more different strings?

Thank you so much :)

XAML CODE

CS CODE

` #region Circulation

public class CirculationItem {
    public string Circulation { get; set; }
    public bool IsSelected { get; set; }
}

private void CirculationData() {
    string configFile = @"C:\Emergenza\Configuration\Configuration.xml";

    XmlDocument xmlDocument = new XmlDocument();
    xmlDocument.Load(configFile);

    XmlNodeList nodes = xmlDocument.SelectNodes("/Config/Paziente/Associazione/Circolo/Value");

    ComboCirculation01.DisplayMemberPath = "Circulation";

    List<CirculationItem> circulationItems = new List<CirculationItem>();

    foreach (XmlNode node in nodes) {
        string circulation = node.InnerText;
        circulationItems.Add(new CirculationItem { Circulation = circulation });
    }

    ComboCirculation01.ItemsSource = circulationItems;
    ComboCirculation01.ItemSelectionChanged += ComboCirculation01_ItemSelectionChanged;
}

private void ComboCirculation01_ItemSelectionChanged(object sender, Xceed.Wpf.Toolkit.Primitives.ItemSelectionChangedEventArgs e) {
    foreach (CirculationItem item in ComboCirculation01.Items) {
        item.IsSelected = ComboCirculation01.SelectedItems.Contains(item);
    }
}

#endregion`

Pastebin XAML CODEhttps://pastebin.com/sgD07g2P Pastebin CS CODEhttps://pastebin.com/YHtaYLnN

— Reply to this email directly, view it on GitHubhttps://github.com/xceedsoftware/wpftoolkit/issues/1752, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A7M3JWZGIQSQUEEJH7Z2J4LXJX6CRANCNFSM6AAAAAAY3FJZTI. You are receiving this because you are subscribed to this thread.Message ID: @.***>

sup3r93 commented 1 year ago

That works great, thank you very much :)

sup3r93 commented 1 year ago

@XceedDanP I apologize if I reopened the topic, but I wanted to avoid opening another one in case I made a mistake I apologize, is it possible with your control to perform this operation?

If I select option "A" all the other options are disabled, if instead I select option "B" options "A" and "C" are disabled