3

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.

DmitryG
  • 17,677
  • 1
  • 30
  • 53
Ranjan Panigrahi
  • 227
  • 2
  • 6
  • 10

3 Answers3

4

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!");
}
DmitryG
  • 17,677
  • 1
  • 30
  • 53
  • Hi, this code is not working for me because i am using a devexpress datagrid control.>>gridview1.columns["Hyperlink"]; line not working , unless the code for button , that is working fine .please guide me what i will do for hyperlink. – Ranjan Panigrahi Jan 22 '13 at 15:08
  • @RanjanPanigrahi [GridView](http://help.devexpress.com/#WindowsForms/CustomDocument3464) is a [View](http://help.devexpress.com/#WindowsForms/CustomDocument3462) for DevExpress XtraGrid control. You can use `((GridView)gridControl1.View).Columns` instead of `gridView1.Columns` – DmitryG Jan 23 '13 at 07:09
1

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

Dimitar Tsonev
  • 3,711
  • 5
  • 40
  • 70
0

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);
        }
    }
}
Olivier de Rivoyre
  • 1,579
  • 1
  • 18
  • 24