Reputation: 117
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).
Upvotes: 0
Views: 1346