I have a ribboncombobox and it bind with a table. As I want student ID will display in the combobox, But when I select a student Id from the ribboncombobox it will give following error.
Can someone please help me.
Error is-
An unhandled exception of type 'System.InvalidCastException' occurred in RibbonControlsLibrary.dll
Additional information: Unable to cast object of type 'System.Data.DataRowView' to type 'Microsoft.Windows.Controls.Ribbon.RibbonComboBoxItem'.
<r:RibbonComboBox Name="childnamecombo" ItemsSource="{Binding}" SelectedValuePath="stid" Margin="34,56,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="168" IsEditable="True" IsReadOnly="True" IsDropDownOpen="false" SelectedIndex="-1" SelectionChanged="selectchildindividualobservation_SelectionChanged">
<r:RibbonComboBox.ItemTemplate >
<DataTemplate >
<TextBlock Text="{Binding stid}"/>
</DataTemplate>
</r:RibbonComboBox.ItemTemplate>
</r:RibbonComboBox>
SQLiteConnection SQLiteCon = new SQLiteConnection();
SQLiteCon.ConnectionString = @"data source=C:\student.s3db";
SQLiteCommand cmd = new SQLiteCommand();
cmd.Connection = SQLiteCon;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from studentrecord";
SQLiteDataAdapter sqlitead = new SQLiteDataAdapter();
sqlitead.SelectCommand = cmd;
DataSet ds = new DataSet();
try
{
sqlitead.Fill(ds, "studentrecord");
// binding data to combobox
childnamecombo.DataContext = ds.Tables["studentrecord"].DefaultView;
// display values in combobox
childnamecombo.SelectedValuePath = ds.Tables["studentrecord"].Columns["stid"].ToString();
}
catch (Exception ex)
MessageBox.Show(ex.Message );
finally
sqlitead.Dispose();
cmd.Dispose();
SQLiteCon.Dispose();