WPF Toolkit: Nullable object must have a value
Posted
by Via Lactea
on Stack Overflow
See other posts from Stack Overflow
or by Via Lactea
Published on 2010-03-18T16:38:37Z
Indexed on
2010/03/18
16:41 UTC
Read the original article
Hit count: 396
Hi All,
I am trying to create some line charts from a dataset and getting an error (WPF+WPF Toolkit + C#):
Nullable object must have a value
Here is a code that I use to add some data points to the chart:
ObservableCollection points = new ObservableCollection();
foreach (DataRow dr in dc.Tables[0].Rows)
{
points.Add(new VelChartPoint()
{
Label = dr[0].ToString(),
Value = double.Parse(dr[1].ToString())
});
}
Here is a class VelChartPoint
public class VelChartPoint : VelObject, INotifyPropertyChanged {
public DateTime Date
{
get;
set;
}
public string Label
{
get;
set;
}
private double _Value;
public double Value
{
get {
return _Value;
}
set {
_Value = value;
var handler = PropertyChanged;
if (null != handler)
{
handler.Invoke(this, new PropertyChangedEventArgs("Value"));
}
}
}
public string FieldName
{
get;
set;
}
public event PropertyChangedEventHandler PropertyChanged;
public VelChartPoint() { }
}
So the problem occures in this part of the code
points.Add(new VelChartPoint
{
Name = dc.Tables[0].Rows[0][0].ToString(),
Value = double.Parse(dc.Tables[0].Rows[0][1].ToString())
}
);
I've made some tests, here are some results i've found out. This part of code does'nt work for me:
string[] labels = new string[] { "label1", "label2", "label3" };
foreach (string label in labels)
{
points.Add(new VelChartPoint
{
Name = label,
Value = 500.0
}
);
}
But this one works fine:
points.Add(new VelChartPoint
{
Name = "LabelText",
Value = double.Parse(dc.Tables[0].Rows[0][1].ToString())
}
);
Please, help me to solve this error.
© Stack Overflow or respective owner