I want to get the checkedlistBox value on variable my code is below can anybody help me
private void CheckPreviousTxn_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
int selected = CheckPreviousTxn.SelectedIndex;
string selecteditem1 = CheckPreviousTxn.CheckedItems.ToString();
if (selected != -1)
{
foreach (string slecteditem in CheckPreviousTxn.CheckedItems)
{
con = new SqlConnection(connectionpath);
cmd = new SqlCommand("select QTNCode as 'QTN Code',STKCODE as 'Item Code',STKDESCP as 'Item Name',Quantity,BaseUnit as 'Unit',Rate,DiscountAmount as 'Discount',Amount,VatPercentage as 'VAT %',TotalTaxAmount as 'VAT Amt' from Tbl_QTNDetail where QTNCode ='" + slecteditem + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
GrdQtnDetail.DataSource = dt;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
i am getting the following exception
Unable to cast object of type 'System.Data.DataRowView' to type 'System.String'
and I am getting the checkedlistBox
value = {System.Windows.Forms.CheckedListBox, Items.Count: 13, Items[0]:QTN0001}