I am doing a mobile application. Someone else is passing me the datatable via a webservice so I get in the following:

    DataTable dt = new DataTable(); // create a datatable dt
    System.Guid guidCustomer = new Guid(Common.sCustomerID); // pass the guid

    dt = ws.BoningRoomOrdersCustomerOrderItems(guidCustomer); // send guid to webservice

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

No problems - loads a listview with the product number and quantity required and in the lvi.Tag I put in the dr (DataRow)

Now my problem is later when someone taps on the listview item I now want to read the lvi.Tag and split it into the 4 parts

How the hell do I do this?

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

        if (lvi.Tag is DataRow)

any ideas?

part 1 is a guid
part 2 is an int
part 3 is another guid
part 4 is a string

thanks for your help

Hi AndreiZ3 and welcome to DaniWeb :)

You need to cast the tag back to a datarow, then you can access each part by their names, using the methods in the Convert class to convert to the datatype required. For example,

ListViewItem lvi = lvProductsOrdered.Items[lvProductsOrdered.SelectedIndices[0]];
if (lvi.Tag.GetType() == typeof(DataRow))
  DataRow dr = (DataRow)(lvi.Tag);
  int qtyOrdered = Convert.ToInt32(dr["QuantityOrdered"]);
  // and so on...