WEB开发网
开发学院图形图像Flash Using The Silverlight DataGrid 阅读

Using The Silverlight DataGrid

 2008-10-24 11:47:00 来源:WEB开发网   
核心提示: C#public Page(){InitializeComponent();//dg.ItemsSource = "H e l l o W o r l d !".Split();List<Data> source = new List<Data>

C#

public Page()
{
  InitializeComponent();
  //dg.ItemsSource = "H e l l o W o r l d !".Split();
  List<Data> source = new List<Data>();
  int itemsCount = 100;
  for (int i = 0; i < itemsCount; i++)
  {
    source.Add(new Data()
    {
      FirstName = "First",
      LastName = "Last",
      Age = i,
      Available = (i % 2 == 0)
    });
  }
  dg.ItemsSource = source;
}

VB

Public Sub New()
  InitializeComponent()
  'dg.ItemsSource = "H e l l o W o r l d !".Split()
  Dim Source As List(Of Data) = New List(Of Data)
  Dim ItemsCount As Integer = 100
  For index As Integer = 1 To ItemsCount
    Source.Add(New Data() With _
    { _
      .FirstName = "First", _
      .LastName = "Last", _
      .Age = index, _   .Available = (index Mod 2 = 0) _
    })
  Next
  dg.ItemsSource = Source
End Sub

When you run this you will notice that columns are created for you. This is because auto-generation takes over, using reflection to create a column for each property in Data, setting the column header to the name of the property, and choosing default column types based on the property type. For instance the Available column is a DataGridCheckBoxColumn. (If you did not want this behavior, but rather wanted to choose your own columns, you can do this by setting the DataGrid's AutoGenerateColumns property to false. For information on choosing your own columns see my post on Defining Columns for a Silverlight DataGrid)

上一页  1 2 3 4 5 6  下一页

Tags:Using The Silverlight

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接