I have a windows forms datagrid,
Dim da As New OleDbDataAdapter(sql, conn)
da.Fill(ds, "providers")
' set the column widths
Dim c0 As New DataGridTextBoxColumn
'c0.TextBox.Enabled = False
c0.MappingName = "PROV_ID"
c0.HeaderText = "ID"
c0.Width = 45
' clear out the table style
dtgResults.TableStyles.Clear()
' create new table style
Dim style As New DataGridTableStyle
' set mapping name to table name
style.MappingName = "providers"
' add column widths to the style
style.GridColumnStyles.Add(c0)
' add style to the data grid
dtgResults.TableStyles.Add(style)
'bind the data source
dtgResults.DataSource = ds.Tables(0)
dtgResults.Refresh()
I want to make PROV_ID clickable, how can I do this?
Thank you,
Burak
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
namespace MyColumnStyles
{
/// <summary>
/// Summary description for LinkLabelColumnStyle.
/// </summary>
public class LinkLabelColumnStyle : DataGridTextBoxColumn
{
#region Variables
private DataLinkLabel columnLinkLabel;
#endregion
#region Properties
public LinkLabel LinkLabel
{
get
{
return this.columnLinkLabel;
}
}
#endregion
#region Constructor
public LinkLabelColumnStyle()
{
this.columnLinkLabel = new DataLinkLabel();
this.columnLinkLabel.Click += new EventHandler(ColumnLinkLabel_Click);
}
#endregion
#region Edit
protected override void Edit(CurrencyManager source, int rowNum, System.Drawing.Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible)
{
base.Edit(source,rowNum,bounds,readOnly,instantText,cellIsVisible);
this.columnLinkLabel.Parent = this.TextBox.Parent;
this.columnLinkLabel.Location = this.TextBox.Location;
this.columnLinkLabel.Size = new Size(this.TextBox.Width,this.TextBox.Height);
this.TextBox.Visible = false;
this.columnLinkLabel.Text = this.TextBox.Text;
this.columnLinkLabel.Visible = true;
this.columnLinkLabel.BringToFront();
this.columnLinkLabel.Focus();
}
#endregion
private void ColumnLinkLabel_Click(object sender, EventArgs e)
{
MessageBox.Show("WooHoo");
}
}
public class DataLinkLabel : LinkLabel
{
private int WM_KEYUP = 257;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_KEYUP)
{
return;
}
base.WndProc (ref m);
}
}
}
In the link label click event handler is where you'll want to put you action code.
Hope this helps.
Thank you Travis for the code.
I had a quick question: is it possible to compile this C# class and
call it from a vb.net project?
Thank you,
Burak
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!