[FlexGrid for WinForms] マージされた固定列や固定行がある場合、横スクロール時に通常列のコンテンツが固定列にはみ出して表示される

文書番号 : 81971     文書種別 : 既知の問題     登録日 : 2017/02/10     最終更新日 : 2017/05/17
文書を印刷する
対象製品
ComponentOne for WinForms
ステータス
修正済み
詳細
固定列や固定行のセルがマージされている場合、横スクロール時に通常列のコンテンツが固定列にはみ出して表示されます。
回避方法
この問題はバージョン2.0.20171.259または4.0.20171.260で修正されました。
修正版の適用方法については、アップデートの方法を参照してください。

修正版を適用しない場合の回避方法は、次の通りです。

C1FlexGridのOwnerDrawCellイベントを使用し、該当する文字列のみをセル内に描画します。

◎サンプルコード(VB)
  Private Sub C1FlexGrid1_OwnerDrawCell(sender As Object, e As OwnerDrawCellEventArgs) Handles C1FlexGrid1.OwnerDrawCell

    Dim fixedWidth As Integer = 0
    For index As Integer = 0 To C1FlexGrid1.Cols.Frozen - 1
      fixedWidth += C1FlexGrid1.Cols(index).WidthDisplay
    Next

    If e.Col >= C1FlexGrid1.Cols.Frozen AndAlso e.Bounds.X < fixedWidth AndAlso e.Bounds.X + e.Bounds.Width > fixedWidth Then
      Dim rect As Rectangle = New Rectangle(fixedWidth, e.Bounds.Y, e.Bounds.Width - (e.Bounds.X - fixedWidth), e.Bounds.Height)
      Dim fmt As StringFormat = StringFormat.GenericTypographic

      Select Case e.Style.TextAlign
        Case TextAlignEnum.CenterBottom
          fmt.Alignment = StringAlignment.Center
          fmt.LineAlignment = StringAlignment.Far
        Case TextAlignEnum.CenterCenter
          fmt.Alignment = StringAlignment.Center
          fmt.LineAlignment = StringAlignment.Center
        Case TextAlignEnum.CenterTop
          fmt.Alignment = StringAlignment.Center
          fmt.LineAlignment = StringAlignment.Near
        Case TextAlignEnum.GeneralBottom, TextAlignEnum.LeftBottom
          fmt.Alignment = StringAlignment.Near
          fmt.LineAlignment = StringAlignment.Far
        Case TextAlignEnum.GeneralCenter, TextAlignEnum.LeftCenter
          fmt.Alignment = StringAlignment.Near
          fmt.LineAlignment = StringAlignment.Center
        Case TextAlignEnum.GeneralTop, TextAlignEnum.LeftTop
          fmt.Alignment = StringAlignment.Near
          fmt.LineAlignment = StringAlignment.Near
        Case TextAlignEnum.RightBottom
          fmt.Alignment = StringAlignment.Far
          fmt.LineAlignment = StringAlignment.Far
        Case TextAlignEnum.RightCenter
          fmt.Alignment = StringAlignment.Far
          fmt.LineAlignment = StringAlignment.Center
        Case TextAlignEnum.RightTop
          fmt.Alignment = StringAlignment.Far
          fmt.LineAlignment = StringAlignment.Near
      End Select

      Dim pos As Point = New Point(e.Bounds.X, e.Bounds.Y)
      e.DrawCell(DrawCellFlags.Background Or DrawCellFlags.Border)
      e.Graphics.DrawString(e.Text, e.Style.Font, New SolidBrush(e.Style.ForeColor), e.Bounds, fmt)
      e.Handled = True
    End If

  End Sub

◎サンプルコード(C#)
    private void c1FlexGrid1_OwnerDrawCell(object sender, C1.Win.C1FlexGrid.OwnerDrawCellEventArgs e)
    {

      int fixedWidth = 0;
      for (int index = 0; index <= c1FlexGrid1.Cols.Frozen - 1; index++)
      {
        fixedWidth += c1FlexGrid1.Cols[index].WidthDisplay;
      }

      if (e.Col >= c1FlexGrid1.Cols.Frozen && e.Bounds.X < fixedWidth && e.Bounds.X + e.Bounds.Width > fixedWidth)
      {
        Rectangle rect = new Rectangle(fixedWidth, e.Bounds.Y, e.Bounds.Width - (e.Bounds.X - fixedWidth), e.Bounds.Height);
        StringFormat fmt = StringFormat.GenericTypographic;

        switch (e.Style.TextAlign)
        {
          case TextAlignEnum.CenterBottom:
            fmt.Alignment = StringAlignment.Center;
            fmt.LineAlignment = StringAlignment.Far;
            break;
          case TextAlignEnum.CenterCenter:
            fmt.Alignment = StringAlignment.Center;
            fmt.LineAlignment = StringAlignment.Center;
            break;
          case TextAlignEnum.CenterTop:
            fmt.Alignment = StringAlignment.Center;
            fmt.LineAlignment = StringAlignment.Near;
            break;
          case TextAlignEnum.GeneralBottom:
          case TextAlignEnum.LeftBottom:
            fmt.Alignment = StringAlignment.Near;
            fmt.LineAlignment = StringAlignment.Far;
            break;
          case TextAlignEnum.GeneralCenter:
          case TextAlignEnum.LeftCenter:
            fmt.Alignment = StringAlignment.Near;
            fmt.LineAlignment = StringAlignment.Center;
            break;
          case TextAlignEnum.GeneralTop:
          case TextAlignEnum.LeftTop:
            fmt.Alignment = StringAlignment.Near;
            fmt.LineAlignment = StringAlignment.Near;
            break;
          case TextAlignEnum.RightBottom:
            fmt.Alignment = StringAlignment.Far;
            fmt.LineAlignment = StringAlignment.Far;
            break;
          case TextAlignEnum.RightCenter:
            fmt.Alignment = StringAlignment.Far;
            fmt.LineAlignment = StringAlignment.Center;
            break;
          case TextAlignEnum.RightTop:
            fmt.Alignment = StringAlignment.Far;
            fmt.LineAlignment = StringAlignment.Near;
            break;
        }

        Point pos = new Point(e.Bounds.X, e.Bounds.Y);
        e.DrawCell(DrawCellFlags.Background | DrawCellFlags.Border);
        e.Graphics.DrawString(e.Text, e.Style.Font, new SolidBrush(e.Style.ForeColor), e.Bounds, fmt);
        e.Handled = true;
      }
    }