Click here to Skip to main content
15,894,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am creating a window based application (6.5) on vs2008. I am trying to bind objects property with DataGrid's cell value:

C#
int rowCount = dataGrid1.BindingContext[dataGrid1.DataSource].Count;
            if (rowCount <= 0)
                return;
            dataGrid1.Select(dataGrid1.CurrentRowIndex);

            System.Data.DataRowView dataRow = ((System.Data.DataRowView)dataGrid1.BindingContext[dataGrid1.DataSource].Current);
            scaleAttachment = new Scale_Attachment();
            scale = new Scale();
            Scale_Details fetchScaleDetail = new Scale_Details();
            fetchScaleDetail.ID = Convert.ToInt32(dataRow.Row.ItemArray[0]);
            fetchScaleDetail.Scale_ID = Convert.ToInt32(dataRow.Row.ItemArray[1]);

For the first time it works fine but for second time when DataGrid has more than one row it gives me error:
(System.Data.DataRowView)dataGrid1.BindingContext[dataGrid1.DataSource].Current Cannot cast '((System.Windows.Forms.CurrencyManager)dataGrid1.BindingContext[dataGrid1.DataSource]).Current' (which has an actual type of to 'System.Data.DataRowViewSystem.Data.DataRowView
Any help is highly appreciated.
Thanks,
Vivek
Posted

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