Hi,

I have loaded a listview with data from a webservice.

    foreach (DataRow dr in dt.Rows)
    {        
      ListViewItem lvi = new ListViewItem(dr["ProductName"].ToString());
      lvi.SubItems.Add(dr["QuantityOrdered"].ToString());
      lvi.SubItems.Add("0");
      lvProductsOrdered.Items.Insert(0, lvi);
      lvi.Tag = dr;
    }

Now when the user taps on the listview item I want to read the data back in:

The list view shows: product, quantityordered, quantityscanned

eg: Product, 10, 0

private void lvProductsOrdered_SelectedIndexChanged(object sender, EventArgs e)
{
  if (lvProductsOrdered.SelectedIndices.Count == 1)
  {
    ListViewItem lvi = lvProductsOrdered.Items[lvProductsOrdered.SelectedIndices[0]];

    if (lvi.Tag.GetType() == typeof(DataRow))
    {
      DataRow dr = (DataRow)(lvi.Tag);

      string s = dr["CustomerOrderItemId"].ToString();

      System.Guid g = new Guid(s);
      Common.gCustomerOrderItemID = g;

      Common.iQtyOrdered = Convert.ToInt32(dr["QuantityOrdered"]);


    }
  }
  else
  { // to do
  }
}

So I can get the product and the quantityOrdered but the 3rd column of quantityScanned which is currently 0, how do I read the value of that?

It is in the listview and not part of the lvi.tag DataRow

Any suggestions?

thanks

Hi there,

If I have understood your question then the answer is to use something like:

lvi.SubItems[2].text

This would return the 0 for the list view item.

Hope this helps.

Nicholas

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.