I have a WPF DataGrid to display PostgreSQL data. It displays a data table with 14 rows. It is an external connection to server and the number of columns change constantly depending on the user parameters. I have created a class called UCS1freqs and I use it to set the frequency values from data for later plotting those values into a scatter chart. The problem is that once it collects all the data it gives me a invalid cast Exception was unhandled (Unable to cast object of type MS.Internal.NamedObject to type System.Data.DataRowView). I know the problem is related to me using DataRowView. I'm new to code and definitely new to WPF. Any help is greatly appreciated
var ucs1Freqs = new List<Ucs1Freq>();
Tapan PatelPosted Sep 22, 2016, 10:54 AM
Nitin SontakkePosted Sep 21, 2016, 11:29 PM
sigfredo santiagoPosted Sep 21, 2016, 6:13 PM
the error is happeningin this line
foreach (DataRowView row in DataGrid1.Items)
Nitin SontakkePosted Sep 21, 2016, 12:18 AM
sigfredo santiagoPosted Sep 21, 2016, 12:10 AM
Thank you for the suggestions. Ichanged the code, but still getting same error. I'm also including the class properties here. Thanks
class Ucs1Freq
{
private double _frequency;
public double Frequency
{
get { return _frequency; }
set { _frequency = value; }
}
}
var ucs1Freqs = new List<Ucs1Freq>();
foreach (DataRowView row in DataGrid1.Items)
{
if (Convert.ToDouble(row.Row.ItemArray[11]) == 28.464258839)
{
var Ucs1freqstring = row.Row.ItemArray[0];
row.Row.ItemArray[0] = Ucs1freqstring;
Ucs1Freq tempFreq = new Ucs1Freq();
tempFreq.Frequency = (double)Ucs1freqstring;
ucs1Freqs.Add(tempFreq);
}
}
Nitin SontakkePosted Sep 20, 2016, 11:47 PM