作成日: 2014/10/08 最終更新日: 2014/10/08
文書種別
使用方法
詳細
マウスでクリックされたセルを取得するには、各マウスクリックイベントでクリックされた座標を取得し、その座標をGetCellFromPointメソッドに引き渡します。
このサンプルでは、右クリック時にクリックされたセルを選択状態にします。
◎サンプルコード(Visual Basic)
◎サンプルコード(C#)
このサンプルでは、右クリック時にクリックされたセルを選択状態にします。
◎サンプルコード(Visual Basic)
Public Sub New()
InitializeComponent()
AddHandler c1DataGrid1.MouseRightButtonDown, AddressOf c1DataGrid1_MouseRightButtonDown
End Sub
Private Sub c1DataGrid1_MouseRightButtonDown(sender As Object, e As MouseButtonEventArgs)
Dim w As Window = Window.GetWindow(Me)
Dim point As Point = e.GetPosition(w)
Dim cell As C1.WPF.DataGrid.DataGridCell = c1DataGrid1.GetCellFromPoint(point)
If cell IsNot Nothing Then
Console.WriteLine(String.Format("Cell Click [{0}, {1}]", cell.Row.Index, cell.Column.Index))
c1DataGrid1.CurrentCell = cell
c1DataGrid1.Selection.Clear()
c1DataGrid1.Selection.Add(cell)
End If
End Sub
InitializeComponent()
AddHandler c1DataGrid1.MouseRightButtonDown, AddressOf c1DataGrid1_MouseRightButtonDown
End Sub
Private Sub c1DataGrid1_MouseRightButtonDown(sender As Object, e As MouseButtonEventArgs)
Dim w As Window = Window.GetWindow(Me)
Dim point As Point = e.GetPosition(w)
Dim cell As C1.WPF.DataGrid.DataGridCell = c1DataGrid1.GetCellFromPoint(point)
If cell IsNot Nothing Then
Console.WriteLine(String.Format("Cell Click [{0}, {1}]", cell.Row.Index, cell.Column.Index))
c1DataGrid1.CurrentCell = cell
c1DataGrid1.Selection.Clear()
c1DataGrid1.Selection.Add(cell)
End If
End Sub
◎サンプルコード(C#)
public KB80987()
{
InitializeComponent();
c1DataGrid1.MouseRightButtonDown += c1DataGrid1_MouseRightButtonDown;
}
void c1DataGrid1_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
Window w = Window.GetWindow(this);
Point point = e.GetPosition(w);
C1.WPF.DataGrid.DataGridCell cell = c1DataGrid1.GetCellFromPoint(point);
if (cell != null) {
Console.WriteLine(String.Format("Cell Click [{0}, {1}]", cell.Row.Index, cell.Column.Index));
c1DataGrid1.CurrentCell = cell;
c1DataGrid1.Selection.Clear();
c1DataGrid1.Selection.Add(cell);
}
}
{
InitializeComponent();
c1DataGrid1.MouseRightButtonDown += c1DataGrid1_MouseRightButtonDown;
}
void c1DataGrid1_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
Window w = Window.GetWindow(this);
Point point = e.GetPosition(w);
C1.WPF.DataGrid.DataGridCell cell = c1DataGrid1.GetCellFromPoint(point);
if (cell != null) {
Console.WriteLine(String.Format("Cell Click [{0}, {1}]", cell.Row.Index, cell.Column.Index));
c1DataGrid1.CurrentCell = cell;
c1DataGrid1.Selection.Clear();
c1DataGrid1.Selection.Add(cell);
}
}
旧文書番号
80987