【问题标题】:Best way to increase RowHeight on a DevExpress GridView?在 DevExpress GridView 上增加 RowHeight 的最佳方法?
【发布时间】:2018-05-16 19:07:48
【问题描述】:

对不起,如果我的解释有误,我是新来的实习生。

我有一个使用 DevExpress 的 VB 前端的 Winforms 应用程序。

它有一个表示 DataTable 的 gridView。

GridView 中的这些列之一用于描述,我相信它是 repositoryItemMemoEdit 列,它用于显示从几行到整个段落的文本。

我发现设置GridView.OptionsView.RowAutoHeight = True 可以让我的行完整地显示文本,但是有时文本太大了。

我正在寻找使行显示第一行或第二行的最佳方法,并让其余文本通过鼠标悬停时出现的工具提示显示,或者显示更多并显示更少按钮扩展和收缩行以适应文本或仅显示第一行。解决方案甚至可以将第一行设为超链接,并使其打开一个新的弹出窗口,哈哈。

谁能指出我正确的方向?我在 DevExpress 上几乎一无所知,他们的大多数论坛答案只是没有可视化表示的代码块,所以我什至看不到它是否是我正在寻找的......

谢谢。

编辑:TLDR:在 GridView 中,允许用户根据需要查看更多文本的最佳方式是什么?

【问题讨论】:

  • This 应该能帮到你
  • 这就是我正在查看的指南。我达到了可以显示文本的第一行或整个文本的程度。但它没有解释或显示我如何允许用户在仅查看单行或整个文本之间进行选择。有什么建议吗?
  • 您是否需要 GridView 可编辑(用户编辑当前数据)?
  • 不,它已经填充了数据。但是,某些列中有复选框。

标签: c# vb.net devexpress


【解决方案1】:

解决方案甚至可以将第一行设为超链接并打开一个新的弹出窗口。

订阅GridView.RowCellClick 事件,订阅GridView.ShowingEditor 事件并显示带有单元格内容的XtraMessageBox

Imports DevExpress.XtraEditors
Imports DevExpress.XtraGrid.Views.Grid

Private Sub GridView1_RowCellClick(sender As Object, e As DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs) Handles GridView1.RowCellClick
    If e.Column.Equals(GridView1.Columns("DesiredColumn")) Then
        XtraMessageBox.Show(GridView1.GetFocusedDataRow()("DesiredColumn").ToString())
    End If
End Sub

Private Sub GridView1_ShowingEditor(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles GridView1.ShowingEditor
    If GridView1.FocusedColumn.Equals(GridView1.Columns("DesiredColumn")) Then
        e.Cancel = True
    End If
End Sub

点击的单元格:

【讨论】:

    【解决方案2】:

    也许最好的方法是处理GridView.CustomDrawCell 事件并在ToolTipController.GetActiveObjectInfo 事件中手动处理。

    private void GridView1_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e)
        {
    
            if (e.Column.FieldName == "DesiredColumn")
            {
                // handle display logic here, this is just POC
                var row = GridView1.GetDataRow(e.RowHandle);
                var text = row["DesiredColumn"].ToString();
    
                if (text.Length > 100) {
                  e.DisplayText = text.Substring(0, 100) + "...";
                  e.Handled = true;
                }
            }
        }
    
    
    private void toolTipController1_GetActiveObjectInfo(object sender, ToolTipControllerGetActiveObjectInfoEventArgs e)
        {
            ToolTipControlInfo info;
            var gv = this.GridControl1.GetViewAt(e.ControlMousePosition) as GridView;
            if (gv == null)
            {
                return;
            }
    
            var hInfo = gv.CalcHitInfo(e.ControlMousePosition);
    
            if ((e.SelectedControl is GridControl))
            {
                if (hInfo.InRowCell)
                {
                    if (hInfo.Column == gv.Columns["DesiredColumn"])
                    {
                        var row = gv.GetDataRow(hInfo.RowHandle);
                        var text = row["DesiredColumn"].ToString;
                            info = new ToolTipControlInfo(this.GridControl1, text);
                            e.Info = info;
                    }
    
                }
            }
        }
    

    【讨论】:

    • OP 正在使用 VB!
    猜你喜欢
    • 1970-01-01
    • 2020-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-27
    • 1970-01-01
    • 1970-01-01
    • 2015-10-01
    相关资源
    最近更新 更多