Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

Created Unassigned: Index-Out-Of-Range exception with DateTime Control [22459]

$
0
0
In method 'protected override void OnValueChanged(' of Main\Source\ExtendedWPFToolkitSolution\Src\Xceed.Wpf.Toolkit\DateTimeUpDown\Implementation\DateTimeUpDown.cs' class, following statement

```
if( info == null)
info = (this.CurrentDateTimePart != DateTimePart.Other) ? this.GetDateTimeInfo( this.CurrentDateTimePart ) : _dateTimeInfoList[ 0 ];

```

was throwing this Index-Out-Of-Range exception.

It is because the '_dateTimeInfoList' had no elements in it (i.e. Length=0), and it was trying to access its first element.

I've fixed it by applying a check '_dateTimeInfoList.Count > 0' before using '_dateTimeInfoList[0]'.

Following is the complete block of code replacing the above code block which fixes the issue:

```
if (info == null)
{
if (this.CurrentDateTimePart != DateTimePart.Other)
{
info = this.GetDateTimeInfo(this.CurrentDateTimePart);
}
else
{
if (_dateTimeInfoList.Count > 0)
{
info = _dateTimeInfoList[0];
}
}
}

```

Viewing all articles
Browse latest Browse all 4964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>