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>();
Nitin SontakkeRank #264 · 9.6K reputationPosted Sep 20, 2016, 7:47 PM EDT
sigfredo santiago5 reputationPosted Sep 20, 2016, 8:10 PM EDT
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 SontakkeRank #264 · 9.6K reputationPosted Sep 20, 2016, 8:18 PM EDT
sigfredo santiago5 reputationPosted Sep 21, 2016, 2:13 PM EDT
the error is happeningin this line
foreach (DataRowView row in DataGrid1.Items)
Nitin SontakkeRank #264 · 9.6K reputationPosted Sep 21, 2016, 7:29 PM EDT
Tapan PatelRank #614 · 3.9K reputationPosted Sep 22, 2016, 6:54 AM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts