0

I am designing a WPF Application for a hospital. I am using SQL Server as my back end. I am using CheckComboBox so I can select multiple values from DropDownList and perform actions based on those selected values. I have tried many posts and google searches to get a complete solution but I got only half solution. Till now I am able to Bind back-end data (Person Table in SQL Server) to the CheckComboBox. It successfully displays items in DropDownList but when I select items it does not display their name. snapshot after selecting some values

I think I am not correctly binding the data. here is my XAML code

<Grid>
    <xctk:CheckComboBox x:Name="_combo" 
                        HorizontalAlignment="Center" 
                        VerticalAlignment="Center" 
                        DisplayMemberPath="Name"
                        ValueMemberPath="Name"
                        SelectedMemberPath="Name"
                        SelectedValue="{Binding SelectedValue}"/>                    
</Grid>

Here is Code Behind File

public partial class TestScreen : Window
{
    public TestScreen()
    {
        InitializeComponent();
        BindTreatmentComboBox(_combo);
    }

    // displaying data in ComboBox
    public void BindTreatmentComboBox(CheckComboBox comboBoxName)
    {
        string ConString = ConfigurationManager.ConnectionStrings["RTS_ManagementModel"].ConnectionString;
        string CmdString = string.Empty;
        SqlConnection conn = new SqlConnection(ConString);
        try
        {
            conn.Open();
            CmdString = "SELECT Name "
                + "FROM Person "
                + "WHERE PersonTypeID = " + 13;
            SqlDataAdapter da = new SqlDataAdapter(CmdString, conn);
            DataSet ds = new DataSet();
            da.Fill(ds, "Person");
            comboBoxName.ItemsSource = ds.Tables["Person"].DefaultView;
        }
        catch (Exception ex)
        {
            Xceed.Wpf.Toolkit.MessageBox msg = new Xceed.Wpf.Toolkit.MessageBox();
            msg.ShowMessageBox(ex.Message.ToString());
        }
        finally
        {
            conn.Close();
        }
    }
}

I want to take some kind of decision based on the selected values (I want to use them in SQL query).

wonea
  • 4,783
  • 17
  • 86
  • 139
Sandeep Sihari
  • 97
  • 2
  • 14
  • I'm trying to resolve your problem. In the middle, please note that in the `ex.Message.ToString()` (third-last row) the `ToString()` is useless, since the `Message` property of an `Exception` is already a string. – Massimiliano Kraus Aug 30 '16 at 16:05
  • ok i will keep in mind that. – Sandeep Sihari Aug 30 '16 at 16:07
  • Second point: `SelectedMemberPath="Name"` is wrong. The documentation says: _"SelectedMemberPath - Gets or sets a path to a value on the source object used to determine whether an item is selected"_ That is, it's a boolean value! Something like "IsSelected", not something like "Name". – Massimiliano Kraus Aug 30 '16 at 16:24
  • Sorry, I tried hard, but I can't reproduce your issue. I set the DisplayMemberPath, and it works both on the comma-separated list and on the DropDownList. – Massimiliano Kraus Aug 30 '16 at 16:37
  • Could you show me your code snippet ? what you did may be i got some idea from that – Sandeep Sihari Aug 30 '16 at 17:02

0 Answers0