Question

I have an UltraGrid which is bound to a DataTable with two columns (Key, Value). I have added 10 rows into the DataTable, and now the 11th row has a URL in the Value column. The URL value gets added fine, but it doesn't work like a hyperlink. To make it work as a hyperlink, how do I need to add this row into the UltraGrid? My code:

DataTable dt = new DataTable();
dt.Columns.Add("Key", typeof(string));
dt.Columns.Add("Value", typeof(string));
ultraGrid.DataSource = dt;

foreach (KeyValuePair<string, string> kvp in dictionary)
{
    dt.Rows.Add(kvp.Key, kvp.Value);
}

// Adding the row which has the URL value.
string url = "SomeURL";
Uri hyperLink = new Uri(url);
dt.Rows.Add("Click this", hyperLink);
Was it helpful?

Solution

While the answer given by U1199880 point to a partially correct solution there is a problem applying that style to the whole column. Every cell in the column will be treated as a link.

Instead you need to intercept the InitializeRow event and check if the current cell of the current row is a valid URI. Then change the cell Style property to the ColumnStyle.URL

private void grd_InitializeRow(object sender, InitializeRowEventArgs e)
{
    if (e.ReInitialize == false)
    {
        UltraGridColumn c = e.Row.Band.Columns["Value"];
        string link = e.Row.GetCellValue(c).ToString();
        if (Uri.IsWellFormedUriString(link, UriKind.Absolute))
            e.Row.Cells["Value"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.URL;
    }
}

OTHER TIPS

When you define your grid columns use the type: Infragistics.Win.UltraWinGrid.ColumnStyle.URL as the column type.

Then the grid will raise a CellLinkClicked event in your code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top