This is a migrated thread and some comments may be shown as answers.

Change column type to hyperlink

3 Answers 259 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 2
Bob asked on 15 May 2012, 04:52 PM
I am binding the datasource to an empty datagrid.  Afterwards, I change the column headers and want to make a particular field a hyperlink.  I saw something in the threads earlier about having to add a new column, link the data to that column and hide the original column.  I'm not sure I understand how to bound data from one column to another.

    Using context As New FES_ThreeWayMatchEntityModel.ThreeWayMatchEntities
        Dim q = From lh In context.Invoice_Header
                Join v In context.Vendors On lh.Vendor_ID Equals v.Vendor_ID
                Select v.Vendor_Name, lh.Shipment_Number, lh.Invoice_Number, lh.Invoice_Date, lh.Invoice_Total
 
        invoiceList.invoiceDataGrid.DataSource = q
    End Using
 
    ' Create the hyperelink column
    Dim hl As New GridViewHyperlinkColumn
    hl.Name = "hlVendorName"
 
    With invoiceList.invoiceDataGrid
        .BestFitColumns()
        .Columns("Vendor_Name").IsVisible = False       ' Hide the original field
 
        .Columns("Shipment_Number").HeaderText = "Lot/Shipment Number"
        .Columns("Invoice_Number").HeaderText = "Invoice Number"
        .Columns("Invoice_Date").HeaderText = "Invoice Date"
        .Columns("Invoice_Date").FormatString = "{0:MM/dd/yyyy}"
        .Columns("Invoice_total").HeaderText = "Invoice Total"
 
        ' Add the hyperlink column
        .Columns.AddRange(hl)
        .Columns.Move(6, 0)
    End With
End Sub


Where or how do I bind the data?

Thanks
Bob

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 17 May 2012, 02:31 PM
Hello Bob,

Thank you for writing.

After your grid is bound and you hide the desired column, add your hyperlink column and set its FieldName to the desired field in the data source. Here is a small sample:
public Form1()
{
    InitializeComponent();
 
    Random r = new Random();
    DataTable table = new DataTable();
    table.Columns.Add("ID", typeof(int));
    table.Columns.Add("Name", typeof(string));
    table.Columns.Add("Bool", typeof(bool));
    table.Columns.Add("DateColumn", typeof(DateTime));
 
    for (int i = 0; i < 10; i++)
    {
        table.Rows.Add(i, "http://www.telerik.com", r.Next(10) > 5 ? true : false, DateTime.Now.AddHours(i));
    }
 
    this.radGridView1.DataSource = table;
    radGridView1.Columns.RemoveAt(1);
 
    GridViewHyperlinkColumn col = new GridViewHyperlinkColumn();
    radGridView1.Columns.Add(col);
    col.Width = 200;
    col.FieldName = "Name";
     
}

I hope this helps. Let us know if you have any other questions,
 
Kind regards,
Stefan
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Bob
Top achievements
Rank 2
answered on 17 May 2012, 03:33 PM
OK - that makes perfect sense.  Must have had a bad day that I couldn't come up with that.
On another note, I was also wondering if the hyperlink column is for URLs only.  Is there a click event or something that I can trap to open another form or perform some other logic on it?  In some cases the user wishes to see a hyperlink instead of a buttone - is there any control or way to "listen" to the click event?

Thanks
0
Stefan
Telerik team
answered on 22 May 2012, 02:11 PM
Hi Bob,

Yes there are such events - HyperlinkOpening and HyperlinkOpened. More information can be found here: http://www.telerik.com/help/winforms/gridview-columns-gridviewhyperlinkcolumn.html.

Let us know if you have any other questions.
 
Regards,
Stefan
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Bob
Top achievements
Rank 2
Answers by
Stefan
Telerik team
Bob
Top achievements
Rank 2
Share this question
or