473,405 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

DataGrid, Hyperlink Columns & Sorting

Hi,

I needed to build a data grid in which the first column has
hyperlinks rather than simple text. I found the following code on this
newsgroup and it works fine except for one problem. When I click the
column headers all the columns sort except the hyperlink one. I
checked the underlying dataview and that does get sorted so it seems
like it is more of a display issue. I am guessing it has something to
do with the hashtable used by the code below but I am not quite sure
how to handle it. Any help will be appreciated.

Thanks,

Rudolph

CODE:
public sealed class DataGridLinkColumn :
System.Windows.Forms.DataGridColumnStyle
{
Hashtable links = new Hashtable();
public event LinkLabelLinkClickedEventHandler LinkClicked;
public DataGridLinkColumn()
{
}
void AddLinkControl(Rectangle r, int rowNum, object data, string text)
{
LinkLabel link = new LinkLabel();
link.Text = text;
link.Parent = this.DataGridTableStyle.DataGrid;
link.BackColor = ((rowNum & 1) == 1)?this.DataGridTableStyle.BackColor
:this.DataGridTableStyle.AlternatingBackColor;
link.Links.Add(0, text.Length, data);
link.Bounds = r;
link.LinkClicked += new
LinkLabelLinkClickedEventHandler(link_LinkClicked) ;
links[rowNum] = link;
this.DataGridTableStyle.DataGrid.Controls.Add(link );
}
protected override void Abort(int rowNum)
{
}
protected override bool Commit(System.Windows.Forms.CurrencyManager
dataSource, int rowNum)
{
return false;
}
protected override void Edit(System.Windows.Forms.CurrencyManager
source,
int rowNum, System.Drawing.Rectangle bounds, bool readOnly, string
instantText, bool cellIsVisible)
{
}
protected override void Edit(System.Windows.Forms.CurrencyManager
source,
int rowNum, System.Drawing.Rectangle bounds, bool readOnly, string
instantText)
{
base.Edit (source, rowNum, bounds, readOnly, instantText);
}
protected override void Edit(System.Windows.Forms.CurrencyManager
source,
int rowNum, System.Drawing.Rectangle bounds, bool readOnly)
{
base.Edit (source, rowNum, bounds, readOnly);
}
protected override int GetMinimumHeight()
{
return FontHeight+2;
}
protected override int GetPreferredHeight(System.Drawing.Graphics g,
object
value)
{
return GetMinimumHeight();
}
protected override System.Drawing.Size
GetPreferredSize(System.Drawing.Graphics g, object value)
{
return new System.Drawing.Size(50, GetMinimumHeight());
}
protected override void Paint(System.Drawing.Graphics g,
System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager
source, int rowNum, bool alignToRight)
{
Paint(
g,bounds,
source,
rowNum,
Brushes.White,
Brushes.Blue,
alignToRight);
}
protected override void Paint(System.Drawing.Graphics g,
System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager
source, int rowNum)
{
Paint( g, bounds, source, rowNum, false );
}
protected override void Paint(
Graphics g,
Rectangle bounds,
CurrencyManager source,
int rowNum,
Brush backBrush,
Brush foreBrush,
bool alignToRight)
{
object o = GetColumnValueAtRow(source, rowNum);
string text = (o==null || o==DBNull.Value)?this.NullText:o.ToString();
if( links.Contains(rowNum) )
{
LinkLabel link = links[rowNum] as LinkLabel;
if( link.Bounds!=bounds )
link.Bounds = bounds;
link.Visible = true;
}
else
{
AddLinkControl( bounds, rowNum, source.List[rowNum], text );
}
}
public override bool ReadOnly
{
get
{
return true;
}
}
public string Format
{
get { return format; }
set { format = value; }
}
public IFormatProvider FormatInfo
{
get { return formatInfo; }
set { formatInfo = value; }
}
string format;
IFormatProvider formatInfo;
protected override void SetDataGrid(DataGrid value)
{
base.SetDataGrid (value);
value.Scroll += new EventHandler(DataGrid_Scroll);
}
protected override void SetDataGridInColumn(DataGrid value)
{
base.SetDataGridInColumn (value);
value.Scroll += new EventHandler(DataGrid_Scroll);
}

private void DataGrid_Scroll(object sender, EventArgs e)
{
foreach( LinkLabel link in this.links.Values )
link.Visible = false;
}
private void link_LinkClicked(object sender,
LinkLabelLinkClickedEventArgs
e)
{
if( LinkClicked!=null )
LinkClicked( sender, e );
}
}
Nov 16 '05 #1
0 5336

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Bruce Pullum | last post by:
I have a datagrid that I am using a DataView with. All works great for the sorting of the columns. However, after I sort the column, and then try and select a data row to edit, the row selected...
0
by: Robert Brinson | last post by:
Hello all! I'm running .NET Framework 1.1 using VS.NET 2003. I've got a mystery with a DataGrid. Below is the definition of the DataGrid from my aspx page: </asp:datagrid><asp:datagrid...
2
by: Alex | last post by:
I'm reposting my issue with some more info. I would like to use a DataGrid to display my DataSet. My DataSet is from a table in a SQL DB. Both columns in the table are strings. I would like...
2
by: ddaniel | last post by:
I have read many posts and seen many papers on the different techniques for sort and filtering datagrids. Many do re-queries against the dB ala Fritz Onion. I am trying to leverage the Dataview....
1
by: Gunjan Garg | last post by:
Hello All, I am working to create a generic datagrid which accepts a datasource(ListData - This is our own datatype) and depending on the calling program customizes itself for sorting,...
4
by: sakieboy | last post by:
I currently have a datagrid with several columns. The first column in the DataGrid is a HyperLinkColumn. When I select a row, I would like for this HyperlinkColumn to fire. I have the mouseover...
17
by: Mike Fellows | last post by:
im trying (unsucessfully) to add a checkbox column to my datagrid i basically have a datagrid that im populating from a dataset Me.DataGrid1.DataSource = ds.Tables(0) the datagrid then has 5...
3
by: TPhelps | last post by:
I have a sample of an unbound (autogeneratecolumns is true) sortable/pagable datagrid that works. I want to change one of the columns to a hyperlink. The examples I find use a bound column. I...
2
by: Mike Baugh | last post by:
I am using visual studio 2005 to develop a form using c# I have 3 datagrids on one form. I can set the row color based on a certain value in a column. However this color applies to all 3...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.