BUG: A DataGrid control that you bind to an ArrayList class in a Windows Form displays the length of the ArrayList members instead of the ArrayList items (820652)
The information in this article applies to:
- Microsoft Visual Studio .NET (2003), Professional Edition
- Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
- Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
- Microsoft Visual Studio .NET (2003), Academic Edition
- Microsoft Visual Studio .NET (2002), Professional Edition
- Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
- Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
- Microsoft Visual Studio .NET (2002), Academic Edition
SYMPTOMSWhen you bind a DataGrid control to an ArrayList class in a Microsoft Windows Form application, the DataGrid displays the length of the ArrayList members, instead of displaying the ArrayList items.WORKAROUNDTo work around this bug, create a wrapper class that returns
the ArrayList items when the Length property is called. To do this, follow these steps:
- Write a class to wrap the members. To do this, follow these
steps:
- Open your existing project in Microsoft Visual Studio
.NET.
- Right-click project
name.
- Point to Add, and then click
Add Class.
- Replace the existing code with the following
code:
Microsoft Visual Basic .NET Code
Public Class dimension
Private m_length As String
Public Sub New(ByVal str As String)
m_length = str
End Sub
Public Property Length() As String
Get
Length = m_length
End Get
Set(ByVal Value As String)
m_length = Value
End Set
End Property
End Class Microsoft Visual C# .NET Code public class dimension
{
private string m_length;
public dimension(string str)
{
m_length=str;
}
public string Length
{
get
{
return m_length;
}
set
{
m_length=value;
}
}
} - Copy the following code to the Form1_Load event:
Visual Basic .NET Code Dim al As New ArrayList()
al.Add(New dimension("one"))
al.Add(New dimension("two"))
al.Add(New dimension("three"))
DataGrid1.DataSource = al Visual C# .NET CodeArrayList al= new ArrayList();
al.Add(new dimension("one"));
al.Add(new dimension("two"));
al.Add(new dimension("three"));
dataGrid1.DataSource=al;
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are
listed at the beginning of this article.
For
additional information about binding a DataGrid control to an ArrayList, click
the following article numbers to view the articles in the Microsoft Knowledge
Base: 316303
HOW TO: Bind a DataGrid Control to
an ArrayList of Objects or Structures by Using Visual C# .NET
316302 HOW TO: Bind a DataGrid Control to an ArrayList of Objects or Structures by Using Visual Basic .NET
Modification Type: | Minor | Last Reviewed: | 2/3/2006 |
---|
Keywords: | kbvs2005swept kbvs2005doesnotapply kbvs2002sp1sweep kbControl KbUIDesign kbWindowsForms kbCtrl kbbug KB820652 kbAudDeveloper |
---|
|