using System; using System.Collections.Generic; using System.Text; using C1.Win.C1FlexGrid; using System.Diagnostics; using System.Drawing; using System.Windows.Forms; namespace LinkableGrid { public class LinkabelGrid:C1FlexGrid { public LinkabelGrid() { CellStyle cs = base.Styles.Add("NewLink"); cs.Font = new Font(base.Font, FontStyle.Underline); cs.ForeColor = Color.Blue; cs = base.Styles.Add("OldLink"); cs.Font = new Font(base.Font, FontStyle.Underline); cs.ForeColor = Color.Purple; } public class HyperLink { public string Text { get; set; } public string LinkUrl { get; set; } public bool Visited { get; set; } public HyperLink(string text,string linkUrl) { Text = text; LinkUrl = linkUrl; Visited = false; } public void Active() { Visited = true; Process.Start(LinkUrl); } public override string ToString() { //convert item# to EC item# return Text; } } protected override void OnOwnerDrawCell(OwnerDrawCellEventArgs e) { if (base[e.Row, e.Col] is HyperLink) { HyperLink link = (HyperLink)base[e.Row, e.Col]; if (link.Visited) { e.Style=base.Styles["OldLink"]; } else { e.Style = base.Styles["NewLink"]; } } base.OnOwnerDrawCell(e); } protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e) { HitTestInfo ht = base.HitTest(e.X, e.Y); bool showHand = false; if (ht.Type == HitTestTypeEnum.Cell) { if (base[ht.Row, ht.Column] is HyperLink) { HyperLink link = (HyperLink)base[ht.Row, ht.Column]; Rectangle rc = base.GetCellRect(ht.Row, ht.Column, false); Graphics g = base.CreateGraphics(); float width = g.MeasureString(link.Text, base.Font).Width; if (e.X - rc.Left <= width) { showHand = true; } else { showHand = false; } if (g != null) { g.Dispose(); } } } this.Cursor = showHand ? Cursors.Hand : Cursors.Default; base.OnMouseMove(e); } protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e) { if (this.Cursor == System.Windows.Forms.Cursors.Hand) { HitTestInfo ht = base.HitTest(e.X, e.Y); if (ht.Type == HitTestTypeEnum.Cell) { if (base[ht.Row, ht.Column] is HyperLink) { HyperLink link = (HyperLink)base[ht.Row, ht.Column]; link.Active(); } } } base.OnMouseDown(e); } } } client code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using LinkableGrid; namespace LinkableGrid { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.Add("Name", typeof(String)); dt.Columns.Add("Description", typeof(String)); dt.Columns.Add("Link", typeof(LinkableGrid.LinkabelGrid.HyperLink)); dt.Columns["Link"].ReadOnly = true; for (int i = 0; i < 20; i++) { string name, desc, url; name = "Google.com"; desc = "Google: search engine"; url = "http://www.google.com"; dt.Rows.Add(new object[] { name, desc, new LinkableGrid.LinkabelGrid.HyperLink("benny", url) }); } this.linkabelGrid1.DataSource = dt; } private void linkabelGrid1_MouseDown(object sender, MouseEventArgs e) { //test user control events fire } } }