How to get the row and cell value in datagrid in silverlight
IT showing error is Invalid cross-thread access in Silverlight app
private void GetRequestStreamCallback(IAsyncResult asynchronousResult)
{
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
Stream postStream = request.EndGetRequestStream(asynchronousResult);
ReqInvoiceHeader _ReqInvoice = new ReqInvoiceHeader();
_ReqInvoice.CardCode = strCmCode.Trim();
_ReqInvoice.CardName = strCmName.Trim();
_ReqInvoice.Remarks = srtRemarks.Trim();
ReqInvoiceLines oInvLine = new ReqInvoiceLines();
for (int i = 0; i < 2; i++)
{
oInvLine.ItemCode = ((TextBlock)DataGridItem.Columns[0].GetCellContent(DataGridItem.SelectedItem)).Text;
oInvLine.Quantity = ((TextBlock)DataGridItem.Columns[1].GetCellContent(DataGridItem.SelectedItem)).Text;
oInvLine.UnitPrice = ((TextBlock)DataGridItem.Columns[2].GetCellContent(DataGridItem.SelectedItem)).Text;
}
MemoryStream ReqMs = new MemoryStream();
DataContractJsonSerializer jsondata = new DataContractJsonSerializer(typeof(ReqLogIn));
jsondata.WriteObject(ReqMs, _ReqInvoice);
ReqMs.Position = 0;
StreamReader sr = new StreamReader(ReqMs);
string postData = sr.ReadToEnd();
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
postStream.Write(byteArray, 0, postData.Length);
postStream.Close();
request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
}
ReqInvoiceLines cLASS
namespace Pos_Silverlight.DataContract
{
[DataContract(Name = "ReqInvoiceLines")]
public class ReqInvoiceLines
{
[DataMember(Name = "Product")]
public string ItemCode { get; set; }
[DataMember(Name = "Qty")]
public string Quantity { get; set; }
[DataMember(Name = "UnitPrice")]
public string UnitPrice { get; set; }
public ReqInvoiceLines()
{
}
public ReqInvoiceLines(string Product, string Qty, string UnitPrice)
{
this.UnitPrice = UnitPrice;
this.Quantity = Qty;
this.ItemCode=ItemCode;
}
}
public class ItemsCollection : Collection<ReqInvoiceLines>
{
public ItemsCollection()
{
Add(new ReqInvoiceLines("hb", "Item Name1", "1"));
Add(new ReqInvoiceLines("del", "Item Name2", "2"));
Add(new ReqInvoiceLines("con", "Item Name3", "3"));
}
}