[英]How to display a RepositoryItemHyperLinkEdit control inside a DevExpress GridControl
I have a DevExpress GridControl in my current WinForms application. 我在当前的WinForms应用程序中有一个DevExpress GridControl。 I need to display a hyperlink control (RepositoryItemHyperLinkEdit) in a column. 我需要在列中显示超链接控件(RepositoryItemHyperLinkEdit)。 I have added the RepositoryItemHyperLinkEdit via designer, but when I am running the application, hyperlink is not displaying. 我已经通过设计器添加了RepositoryItemHyperLinkEdit,但是当我运行应用程序时,超链接没有显示。
Like to display buttons we are using: 喜欢显示我们使用的按钮:
repositoryItemButtonEdit1.Buttons[0].Kind = DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph;
repositoryItemButtonEdit1.Buttons[0].Caption = "Get Sql Query";
So please tell me what I will write to display hyperlink in a column. 所以请告诉我我要编写什么来显示列中的超链接。
You can use the following code to display hyperlink in grid column: 您可以使用以下代码在网格列中显示超链接:
GridColumn hyperLinkColumn = gridView1.Columns["Hyperlink"];
//...
RepositoryItemHyperLinkEdit hyperLinkEdit = new RepositoryItemHyperLinkEdit();
hyperLinkColumn.ColumnEdit = hyperLinkEdit; // this line associated hyperlink with column
hyperLinkEdit.OpenLink += hyperLinkEdit_OpenLink;
//...
void hyperLinkEdit_OpenLink(object sender, OpenLinkEventArgs e) {
MessageBox.Show("HyperLinkEdit clicked!");
}
If you want to display aditional button in the same column you can use the following approach: 如果要在同一列中显示aditional按钮,可以使用以下方法:
hyperLinkEdit.Buttons[0].Kind = ButtonPredefines.Glyph;
hyperLinkEdit.Buttons[0].Caption = "Get SQL Query";
hyperLinkEdit.ButtonClick += hyperLinkEdit_ButtonClick;
hyperLinkColumn.ShowButtonMode = ShowButtonModeEnum.ShowAlways; // always display button in this column
//...
void hyperLinkEdit_ButtonClick(object sender, ButtonPressedEventArgs e) {
MessageBox.Show("HyperLinkEdit's button clicked!");
}
You didn't mentioned that you've set up the ColumnEdit property of the column to the repository item. 您没有提到您已将列的ColumnEdit属性设置为存储库项。 If you haven't: 如果你还没有:
Note that you may have to use the gridView_MouseUp event in order to catch the click event without waiting that the grid give the focus to the cell. 请注意,您可能必须使用gridView_MouseUp事件才能捕获click事件,而无需等待网格将焦点放在单元格上。
gridColumn.ColumnEdit = new RepositoryItemHyperLinkEdit();
gridColumn.OptionsColumn.ReadOnly = true;
gridColumn.OptionsColumn.AllowEdit = false;
gridView.MouseUp += gridView_MouseUp;
private void gridViewDesk_MouseUp(object sender, MouseEventArgs e)
{
GridView gridView = (GridView) sender;
if (e.Button == MouseButtons.Left && e.Clicks == 1)
{
GridHitInfo hitInfo = gridView.CalcHitInfo(e.Location);
if (hitInfo.InRowCell && hitInfo.Column == this.gridColumn)
{
MessageBox.Show("Click " + hitInfo.RowHandle);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.