简体   繁体   English

Infragistics UltraGrid中的超链接单元

[英]Hyperlink cell in Infragistics UltraGrid

I have an UltraGrid which is bound to a DataTable with two columns (Key, Value). 我有一个UltraGrid ,它绑定到一个DataTable有两列(Key,Value)。 I have added 10 rows into the DataTable, and now the 11th row has a URL in the Value column. 我在DataTable中添加了10行,现在第11行在Value列中有一个URL。 The URL value gets added fine, but it doesn't work like a hyperlink. URL值被添加正常,但它不像超链接那样工作。 To make it work as a hyperlink, how do I need to add this row into the UltraGrid? 要使其作为超链接工作,我如何将此行添加到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);

While the answer given by U1199880 point to a partially correct solution there is a problem applying that style to the whole column. 虽然U1199880给出的答案指向部分正确的解决方案,但是将该样式应用于整个列存在问题。 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. 相反,您需要拦截InitializeRow事件并检查当前行的当前单元格是否是有效的URI。 Then change the cell Style property to the ColumnStyle.URL 然后将单元格样式属性更改为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;
    }
}

When you define your grid columns use the type: Infragistics.Win.UltraWinGrid.ColumnStyle.URL as the column type. 定义网格列时,请使用类型: Infragistics.Win.UltraWinGrid.ColumnStyle.URL作为列类型。

Then the grid will raise a CellLinkClicked event in your code. 然后网格将在您的代码中引发CellLinkClicked事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM