Print Page | Close Window

Binding to a DataGridViewLinkColumn

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=391
Printed Date: 11-Jun-2026 at 10:48pm


Topic: Binding to a DataGridViewLinkColumn
Posted By: kid_kaneda
Subject: Binding to a DataGridViewLinkColumn
Date Posted: 28-Aug-2007 at 2:52pm

Hi

I'm displaying a list of fields in a DataGridView.  One of the columns is a web address, so I'd like to use DataGridViewLinkColumn to display a hyperlink.  The DataGridViewBindingManager only gives DataGridViewTextboxColumn and DataGridViewComboboxColumn as options for the column.  Is there a way I can get the binding manager to create a Link column instead?
 
NB: the list is readonly so I don't have to worry about 2 way binding.
 
Regards
 
Kaneda



Replies:
Posted By: davidklitzke
Date Posted: 28-Aug-2007 at 3:16pm
The DataGridView has extremely limited options for its column editors.  For example, you can't even get a decent editor for a date field.
 
You could try looking yourself for a link column editor, but I doubt that you will have much luck.
 
If you want good editors for grid columns, try DevExpress or Infragistics grids.
 


Posted By: kid_kaneda
Date Posted: 28-Aug-2007 at 3:22pm
Hi David
 
Thanks for the super quick reply, but I'm not looking for an editor.  I just want to use the standard .net DataGridViewLinkColumn class instead of a DataGridViewTextboxColumn.
 
Any ideas?


Posted By: davidklitzke
Date Posted: 28-Aug-2007 at 3:26pm
That's the way the DataGridView works.  You get the same DataGridViewTextBoxColumn if your data field is a date.
 


Posted By: kid_kaneda
Date Posted: 28-Aug-2007 at 4:17pm
Sorry David, I'm not following you :(
 
The standard .NET 2.0 DataGridView has a specific DataGridViewLinkColumn column type that you can select when defining the columns (outside of DevForce).  I can get the DataGridView to show the column as hyperlinks by selecting the .NET DataGridViewLinkColumn type in the Visual Studio columns editor. 
 
The problem is that if I try to use the DataGridViewBindingManager to manage the bindings can't set the column type to DataGridViewLinkColumn as I would do outside of DevForce.   It doesn't give me that option for that column type in the control type drop down.
 
Incidently I can sort of get what I want by changing the column type DataGridViewLinkColumn in the VS column editor after i've added it with the DGVBM which looks right at design time but at run-time of course the DGVBM thinks the column is missing so adds a second column as textbox column, so I get duplicate columns - one with the link as I want it and one with the column as a textbox. 
 
I guess the problem is that according to the msdn documentation the DataGridViewLinkColumn actually behaves more like a button than texbox.  When viewed from that perspective it makes a little more sense why DevForce doesn't offer it as bindable column type (you wouldn't ordinarily bind a button to anything), but still since it is possible to bind to it when not using the DataGridViewBindingManager it would be nice if we could do it with DevForce too.
 
Thanks for your help, and your quick responses.


Posted By: davidklitzke
Date Posted: 28-Aug-2007 at 5:23pm
I'll have someone on our team with more expertise in grid column binders than I have look into this.


Posted By: joshpainter
Date Posted: 28-Aug-2007 at 8:15pm
This is so weird...I was just about to post a new topic about how I got DataGridViewLinkColumns working and wondering if there was a way to get designer support.
 
I've created a class like this:
 

 

public class LinkViewColumnBinder : DataGridViewColumnBinder

{

// Methods

public override void BindColumn(DataGridViewColumn pColumn, ViewDescriptor pViewDescriptor)

{

base.BindColumn(pColumn, pViewDescriptor);

DataGridViewLinkColumn column = (DataGridViewLinkColumn)pColumn;

IDataConverter dataConverter = pViewDescriptor.DataConverter;

}

public override DataGridViewColumn CreateColumn()

{

return new DataGridViewLinkColumn();

}

protected override double GetBaseFitness(IDataConverter pConverter)

{

return base.GetStandardTextBoxFitness(pConverter);

}

// Properties

public override Type ControlType

{

get

{

return typeof(DataGridViewLinkColumn);

}

}

}

 
 
Then you need to open up the designer code-behind file and find the DataGridViewBindingManager section, and you'll see where it declares the column types.  Change DataGridViewTextColumn to DataGridViewLinkColumn.  Now in your form constructor, above InitializeComponent(), add this line:
 

DataGridViewBinderMap.Instance.UpdateMap(typeof(LinkViewColumnBinder));

 
This seems to work great.  Problem is, when you open up the designer for the DataGridViewBindingManager, it shows "empty" for the column type and complains when you try to save it.  So if I knew how to tell the designer about my new type I think we'd be in business!


Posted By: kid_kaneda
Date Posted: 29-Aug-2007 at 10:09am
Thanks David and Josh,  I'll give Josh's suggestion a go.  
 
Luckily for me changing this column to hyperlinks is the last change request outstanding in the project so hopefully I won't have to go back into the DataGridViewBindingManager again too soon :)  but it it would be good if DevForce could support the DataGridViewLinkColumn more directly.
 
Thanks for your help

Kaneda



Print Page | Close Window