Daniel Rabinovits

Daniel Rabinovits

  • NA
  • 34
  • 7.6k

Initially my ListView shows blank

Apr 10 2019 8:32 PM
private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
listView1.Items.Clear();
Approved = false;
string connString = "Data Source=LAPTOP-JTLIEU9Q\\SQLEXPRESS;Initial Catalog=Stores;User ID=sa;Password=Afula1964";
SqlConnection sqlConn = new SqlConnection(connString);
SqlDataAdapter sqlDA = new SqlDataAdapter("spOrderDetails", sqlConn);
sqlDA.SelectCommand.CommandType = CommandType.StoredProcedure;
sqlDA.SelectCommand.Parameters.Add("@OrderID", SqlDbType.VarChar).Value = listBox1.SelectedItem;
DataTable dtSearchResult = new DataTable();
sqlDA.Fill(dtSearchResult);
int fc = dtSearchResult.Columns.Count;
foreach (DataRow row in dtSearchResult.Rows)
{
string[] subitems = new string[fc+1];
object[] o = row.ItemArray;
for (int i = 0; i < fc+1; i++)
{
if (i == 0)
{
subitems[i] = "";
Approved = true;
}
else
{
subitems[i] = o[i-1].ToString();
}
}
if (subitems[4] == "True")
{
subitems[4] = "Yes";
}
else
{
subitems[4] = "No";
}
ListViewItem item = new ListViewItem(subitems);
listView1.Items.Add(item);
}
if (fc > 0)
{
button1.Enabled = true;
}
}

Answers (1)