リストボックスのようなトグル選択を実現するには?(WorkBook/Sheet)

文書番号 : 18341     文書種別 : 使用方法     最終更新日 : 2005/07/09
文書を印刷する
対象製品
El Tabelle for .NET 3.0J
詳細
標準の ListBox コントロールでは、SelectionMode=MultiSimple を使用することで、スペースキーやマウスクリックによるアイテムのトグル選択が可能です。
WorkBook/Sheet コントロールでは、これと同様の選択は提供されておらず、チェックボックス型セルによる代替処理のみが可能でした(参考:製品に付属する CheckRow サンプル)。

アセンブリ バージョン v3.1.2005.0615 以降では、アクティブセルの枠線をカスタマイズする機能が提供されたため、チェックボックス型セルを使用する方法よりも ListBox コントロールに近い外観を実現できます。

[Visual Basic]
Private Sub Form1_Load(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles MyBase.Load
  Sheet1.HighlightColor = Color.White
  Sheet1.ViewMode = GrapeCity.Win.ElTabelle.ViewMode.Row
  Sheet1.EditType = GrapeCity.Win.ElTabelle.EditType.ReadOnly
  Sheet1.SelectionType = GrapeCity.Win.ElTabelle.SelectionType.Single
  Sheet1.ActiveBorder = New GrapeCity.Win.ElTabelle.BorderLine(Color.Black, _
    GrapeCity.Win.ElTabelle.BorderLineStyle.Dotted)

  Sheet1.CellRange = New GrapeCity.Win.ElTabelle.Range("*:*")
  Sheet1.SetBorder(New GrapeCity.Win.ElTabelle.Range("*:*"), _
    New GrapeCity.Win.ElTabelle.BorderLine( _
    Sheet1.GridLine.Color, GrapeCity.Win.ElTabelle.BorderLineStyle.Thin), _
    GrapeCity.Win.ElTabelle.Borders.All)
End Sub

Private Sub Sheet1_KeyDown(ByVal sender As Object, _
  ByVal e As System.Windows.Forms.KeyEventArgs) Handles Sheet1.KeyDown
  If e.KeyCode = Keys.Space Then
    Sheet1.BeginUpdate()
    Dim intActiveRow As Integer = Sheet1.ActivePosition.Row
    If Sheet1.Rows(intActiveRow).BackColor.Equals(Color.Empty) Then
      Sheet1.Rows(intActiveRow).BackColor = SystemColors.Highlight
      Sheet1.Rows(intActiveRow).ForeColor = SystemColors.HighlightText
    Else
      Sheet1.Rows(intActiveRow).BackColor = Color.Empty
      Sheet1.Rows(intActiveRow).ForeColor = Color.Empty
    End If
    Sheet1.EndUpdate()
  End If
End Sub

Private Sub Sheet1_CellClick(ByVal sender As Object, _
  ByVal e As GrapeCity.Win.ElTabelle.ClickEventArgs) Handles Sheet1.CellClick
  Call Sheet1_KeyDown(sender, New Windows.Forms.KeyEventArgs(Keys.Space))
End Sub


[C#]
private void Form1_Load(object sender, System.EventArgs e)
{
  sheet1.HighlightColor = Color.White;
  sheet1.ViewMode = GrapeCity.Win.ElTabelle.ViewMode.Row;
  sheet1.EditType = GrapeCity.Win.ElTabelle.EditType.ReadOnly;
  sheet1.SelectionType = GrapeCity.Win.ElTabelle.SelectionType.Single;
  sheet1.ActiveBorder = new GrapeCity.Win.ElTabelle.BorderLine(Color.Black,
    GrapeCity.Win.ElTabelle.BorderLineStyle.Dotted);

  sheet1.CellRange = new GrapeCity.Win.ElTabelle.Range("*:*");
  sheet1.SetBorder(new GrapeCity.Win.ElTabelle.Range("*:*"),
    new GrapeCity.Win.ElTabelle.BorderLine(
    sheet1.GridLine.Color, GrapeCity.Win.ElTabelle.BorderLineStyle.Thin),
    GrapeCity.Win.ElTabelle.Borders.All);
}

private void sheet1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
  if(e.KeyCode == Keys.Space)
  {
    sheet1.BeginUpdate();
    int intActiveRow = sheet1.ActivePosition.Row;
    if(sheet1.Rows[intActiveRow].BackColor.Equals(Color.Empty))
    {
      sheet1.Rows[intActiveRow].BackColor = SystemColors.Highlight;
      sheet1.Rows[intActiveRow].ForeColor = SystemColors.HighlightText;
    }
    else
    {
      sheet1.Rows[intActiveRow].BackColor = Color.Empty;
      sheet1.Rows[intActiveRow].ForeColor = Color.Empty;
    }
    sheet1.EndUpdate();
  }
}

private void sheet1_CellClick(object sender, GrapeCity.Win.ElTabelle.ClickEventArgs e)
{
  sheet1_KeyDown(sender, new System.Windows.Forms.KeyEventArgs(Keys.Space));
}


最新の修正版はこちら からダウンロードできます。
キーワード
HowTo

この文書は、以前は次のFAQ IDで公開されていました : 7574