如何为Winforms DataGrid控件添加超链接列?
现在我正在添加一个字符串列,如下所示
DataColumn dtCol = new DataColumn(); dtCol.DataType = System.Type.GetType("System.String"); dtCol.ColumnName = columnName; dtCol.ReadOnly = true; dtCol.Unique = false; dataTable.Columns.Add(dtCol);
我只需要它是一个超链接,而不是一个字符串。我正在使用C#和framework 3.5
使用 DataGridViewLinkColumn .
DataGridViewLinkColumn links = new DataGridViewLinkColumn(); links.UseColumnTextForLinkValue = true; links.HeaderText = ColumnName.ReportsTo.ToString(); links.DataPropertyName = ColumnName.ReportsTo.ToString(); links.ActiveLinkColor = Color.White; links.LinkBehavior = LinkBehavior.SystemDefault; links.LinkColor = Color.Blue; links.TrackVisitedState = true; links.VisitedLinkColor = Color.YellowGreen; DataGridView1.Columns.Add(links);
你可能会对 this example