Pergunta

I have a DevExpress GridControl in my current WinForms application. I need to display a hyperlink control (RepositoryItemHyperLinkEdit) in a column. I have added the RepositoryItemHyperLinkEdit via designer, but when I am running the application, hyperlink is not displaying.
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.

Foi útil?

Solução

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:

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!");
}

Outras dicas

You didn't mentioned that you've set up the ColumnEdit property of the column to the repository item. If you haven't:

Repository Item

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.

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);
        }
    }
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top