2012-10-31 32 views
0

是否有可能在Silverlight DataGrid中有一個列有不同類型的控件的行?例如,列的前兩行應該是文本,接下來的兩行應該有按鈕,然後接下來的6行將有複選框。我需要在後面的代碼中構建它。任何幫助,將不勝感激。silverlight在後面的代碼中建立一個數據網格

+0

感謝您的回覆。事實證明,我使用了一個Flex Grid組件來完成我所需要的功能。 –

回答

0

也許下面的代碼給出了你的想法。

 foreach (var item in ItemList) 
     { 
      //Row definition and column definitions are similar 
      LayoutRoot.RowDefinitions.Add(new RowDefinition() 
      { Height = GridLength.Auto});   

      HelloObject hl=new HelloPObject(); 

      //Attached property imeplemantation 
      Grid.SetRow(hl,Layout2.RowDefinitions.Count); 

      //You may add any UIElement as Children 
      LayoutRoot.Children.Add(hl);     
     } 

編輯:對不起,我沒有實現datagrid。

對於datagrid也有可能, AFAIK Telerik的radgridview爲您提供了行索引。但是您可以自己管理。

除此之外,當您點擊網格時,此順序可能會丟失,具體取決於列的排序成員路徑。但是,您可以根據DataGrid的ItemsSource元素中的屬性切換CellTemplate。

DataGrid grid = new DataGrid(); 
     int rowNdx = 0; 
     grid.LoadingRow += (s, a) => 
      {      
       DataGridCell cell = myList.Columns[0].GetCellContent(a.Row).Parent as DataGridCell; 
       switch (rowNdx) 
       { 
        case 0: 
         cell.Content = new TextBlock() { Text= "Click" }; 
         break; 
        default: 
         cell.Content = new Button() { Content = "Click" };      
         break; 
       } 
       rowNdx++;      
      }; 
+0

這可能適用於我,但我確實有一個問題。是否有可能在代碼背後的數據網格中做到這一點? –

相關問題