Skip to main content

Microsoft Silverlight

Unanswered Question Data GridRSS Feed

(0)

Stephen Hewison
Stephen ...

Member

Member

0 points

8 Posts

Data Grid

Is there a bug in the data grid?

 I'm trying to bind a web service object.  The object contains a 0 length byte array.  When the dispatcher fires for the databind event after setting the item source I get an index out of range exception.

 Anyone else had this problem?

Regards,

Steve

mchlsync
mchlsync

Star

Star

14606 points

2,730 Posts

Silverlight MVP

Re: Data Grid

Hello,

In order to know whether the cause is because of web service or datagrid, I would suggest you to loop through and check whether you get any data or not without binding with Datagrid.

You are able to retreieve that data successfully but you can't bind it then please let me know the structure of class and data that you are returning from the service.

If you have simple project then please send it to me mchlsync AT gmail DOT com.

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Regards,
Michael Sync
Silverlight MVP

Blog : http://michaelsync.net


Stephen Hewison
Stephen ...

Member

Member

0 points

8 Posts

Re: Data Grid

Hi,

Thanks for your response.  I don't have a simple project.  This is part of a large MIS project.

The following is the class.  Using LINQ and a VARBINARY to store the RegistrationPin I have to set the registration pin to new byte[] {} to get it parse to a Binary and save to the database.

There were definately 2 records.  Checked this at the point item source was assigned.  Removing the item source assignment stopped the error presenting.  Removing the 0 length array also stopped the error from presenting.  The property in question is not bound to a column in the data grid.  I know its difficult to be sure about which event is causing certain errors as they all fire on the dispatcher but I've done some careful variable changes to ensure that it's the assignment of the item source which causes the error to present.

[Serializable]

public class ClassA

{

public long ID { get; set; }public byte[] RegistrationPin { get; set; }

}

[
Serializable]

public class ClassACollection : System.Collections.CollectionBase

{

public ClassA this[int index] { get { return (ClassA)List[index]; } set { List[index] = value; } }public int Add(ClassA item) { return List.Add(item); }

}

 The set method includes the following line to ensure the value parses to Binary:

classAInst.RegistrationPin == null ? (Binary)(new byte[] {}) : (Binary)classAInst.RegistrationPin);

Collecting the data I had the following line:

 classAInst.RegistrationPin = LINQresult.RegistrationPin.ToArray();

This would turn the Binary back to a 0 length array and on item source assignment create an error.  Changing the code to the following negated the problem:

classAInst.RegistrationPin = LINQresult.RegistrationPin.ToArray();

if (classAInst.RegistrationPin.Length == 0)
classAInst.RegistrationPin = null;

Regards,

Steve

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities