Click here to Skip to main content
15,903,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);
}


C#
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"));

        }
    }
Posted
Updated 26-May-13 9:51am
v2

1 solution

Use the cell content property.
For e.g.
string s=(TextBlock) myGrid.Columns[1].GetCellContent(myGrid.SelectedItem);
 
Share this answer
 
Comments
DhananjayanP 26-May-13 15:08pm    
It's show is error:Connect implicitly convert type"System.Windows.controls.TextBlock"to String
DhananjayanP 26-May-13 15:09pm    
this is my code :string s = (TextBlock)DataGridItem.Columns[1].GetCellContent(DataGridItem.SelectedItem);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900