Infragistics超网格列中的添加按钮+文本

问题描述 投票:2回答:4

我正在使用Infragistics 2013版本。我有一个要求,我必须在winforms ultragrid的列中添加一个按钮以及一个文本。该按钮将打开一个弹出屏幕,允许用户选择一个值,该值将以文本形式显示在网格的列中。

谢谢。

winforms infragistics ultrawingrid wingrid
4个回答
6
投票

将列的Style设置为ColumnStyle .EditButton。例如:

UltraGrid1.DisplayLayout.Bands(0).Columns("ColName").Style = Infragistics.Win.UltraWinGrid.ColumnStyle.EditButton 

然后您可以处理UltraGrids CellButtonClicked事件,以了解单击按钮的时间,e.Cell将让您知道单击了哪个单元:

Private Sub UltraGrid1_ClickCellButton(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.CellEventArgs) Handles ultraGrid1.ClickCellButton
   Debug.WriteLine("Button in " & e.Cell.Value.ToString() & " cell was clicked.")
End Sub

2
投票

只是稍微扩展一下答案:如果您希望按钮始终可见(而不是仅仅单击包含该按钮的单元格时,您可能还需要设置ButtonDisplayStyle:

UltraGrid1.DisplayLayout.Bands(0).Columns("ColName").ButtonDisplayStyle = UltraWinGrid.ButtonDisplayStyle.Always

此外,如果您想进一步控制按钮的外观或位置,则Infragistics的Mike Saltzman的此信息可能会有用:

[如果您希望按钮左对齐,则相同的单元格,或不填充整个单元格但包含文本的按钮和/或图像,您可以使用编辑器。基本方法是像这样:

1)将编辑器控件添加到您的表单(例如UltraTextEditor,用于例)。

2)使用ButtonsLeft和/或ButtonsRight集合添加您想要的按钮。您可以设置每个按钮的文本和外观。

3)在代码中,将列(或单元格)的EditorControl设置为编辑器控件。这本质上就像设置样式,但在更健壮的方法。

4)要处理按钮的单击事件,请处理事件在编辑器上-而不是网格上。例如,如果这只是正常现象按钮,则可以使用EditorButtonClick。事件args将通过您一个上下文,它将返回按钮所在的网格单元点击。


1
投票

确定。

必须将列样式设置为EditButton。

UltraGrid1.DisplayLayout.Bands(0).Columns("ColName").Style = Infragistics.Win.UltraWinGrid.ColumnStyle.EditButton

0
投票

简单。

 private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e)
        {
            // We only need to do this the first time the row is initialized.
            if (e.ReInitialize == false)
            {
                e.Row.Cells["Button"].Value = "Click Here";
            }
        }
        }
© www.soinside.com 2019 - 2024. All rights reserved.