作成日: 2013/06/21 最終更新日: 2013/06/21
文書種別
使用方法
詳細
セルにボタンを表示するには、DataGridTemplateColumn列を作成して、CellTemplateプロパティにボタンを配置します。
また、セルクリック時に行数を取得するには、ボタンクリックイベントでsenderの親(DataGridCellPresenter型)のRow.Indexプロパティを取得します。
◎サンプルコード(XAML)
◎サンプルコード(Visual Basic)
◎サンプルコード(C#)
また、セルクリック時に行数を取得するには、ボタンクリックイベントでsenderの親(DataGridCellPresenter型)のRow.Indexプロパティを取得します。
◎サンプルコード(XAML)
<c1:C1DataGrid Name="c1DataGrid1">
<c1:C1DataGrid.Columns>
<c1:DataGridTemplateColumn>
<c1:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="ボタン" Click="Button_Click" />
</DataTemplate>
</c1:DataGridTemplateColumn.CellTemplate>
</c1:DataGridTemplateColumn>
</c1:C1DataGrid.Columns>
</c1:C1DataGrid>
<c1:C1DataGrid.Columns>
<c1:DataGridTemplateColumn>
<c1:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="ボタン" Click="Button_Click" />
</DataTemplate>
</c1:DataGridTemplateColumn.CellTemplate>
</c1:DataGridTemplateColumn>
</c1:C1DataGrid.Columns>
</c1:C1DataGrid>
◎サンプルコード(Visual Basic)
Imports C1.WPF.DataGrid
Private Sub Button_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
Dim button = TryCast(sender, Button)
Dim presenter = TryCast(button.Parent, DataGridCellPresenter)
MessageBox.Show(presenter.Row.Index & "行目のボタン")
End Sub
Private Sub Button_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
Dim button = TryCast(sender, Button)
Dim presenter = TryCast(button.Parent, DataGridCellPresenter)
MessageBox.Show(presenter.Row.Index & "行目のボタン")
End Sub
◎サンプルコード(C#)
using C1.WPF.DataGrid;
private void Button_Click(object sender, RoutedEventArgs e)
{
var button = sender as Button;
var presenter = button.Parent as DataGridCellPresenter;
MessageBox.Show(presenter.Row.Index + "行目のボタン");
}
private void Button_Click(object sender, RoutedEventArgs e)
{
var button = sender as Button;
var presenter = button.Parent as DataGridCellPresenter;
MessageBox.Show(presenter.Row.Index + "行目のボタン");
}
旧文書番号
80172