作成日: 2017/07/31 最終更新日: 2017/07/31
文書種別
使用方法
詳細
SPREAD for WPFでは、セルがクリックされたときのイベントは用意されていませんが、PreviewMouseLeftButtonDownイベントとHitTestメソッドを使用して、セルのクリックを検出することができます。
次のサンプルコードは、クリックされたセルの値を取得する例です。
◎サンプルコード(VB)
◎サンプルコード(C#)
次のサンプルコードは、クリックされたセルの値を取得する例です。
◎サンプルコード(VB)
Private Sub GcSpreadGrid1_PreviewMouseLeftButtonDown(sender As Object, e As MouseButtonEventArgs) Handles GcSpreadGrid1.PreviewMouseLeftButtonDown Dim hitInfo As GrapeCity.Windows.SpreadGrid.HitTestInfo = GcSpreadGrid1.HitTest(e.GetPosition(GcSpreadGrid1)) If TypeOf hitInfo Is GrapeCity.Windows.SpreadGrid.CellHitTestInfo Then Dim cellHitInfo As GrapeCity.Windows.SpreadGrid.CellHitTestInfo = DirectCast(hitInfo, GrapeCity.Windows.SpreadGrid.CellHitTestInfo) If cellHitInfo.Area = GrapeCity.Windows.SpreadGrid.SpreadArea.Cells Then Dim val = GcSpreadGrid1(cellHitInfo.RowIndex, cellHitInfo.ColumnIndex).Value End If End If End Sub
◎サンプルコード(C#)
public MainWindow()
{
InitializeComponent();
// イベントの関連付け
gcSpreadGrid1.PreviewMouseLeftButtonDown += gcSpreadGrid1_PreviewMouseLeftButtonDown;
}
void gcSpreadGrid1_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
GrapeCity.Windows.SpreadGrid.HitTestInfo hinfo = gcSpreadGrid1.HitTest(e.GetPosition(gcSpreadGrid1));
if (hinfo is GrapeCity.Windows.SpreadGrid.CellHitTestInfo)
{
GrapeCity.Windows.SpreadGrid.CellHitTestInfo cellinfo = (GrapeCity.Windows.SpreadGrid.CellHitTestInfo)hinfo;
if(cellinfo.Area == GrapeCity.Windows.SpreadGrid.SpreadArea.Cells)
{
var val = gcSpreadGrid1[cellinfo.RowIndex, cellinfo.ColumnIndex].Value;
}
}
}
関連情報
旧文書番号
40838