New Posts New Posts RSS Feed: Binding to a DataGridViewLinkColumn
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Binding to a DataGridViewLinkColumn

 Post Reply Post Reply
Author
kid_kaneda View Drop Down
Newbie
Newbie
Avatar

Joined: 28-Aug-2007
Posts: 6
Post Options Post Options   Quote kid_kaneda Quote  Post ReplyReply Direct Link To This Post Topic: Binding to a DataGridViewLinkColumn
    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
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post 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.
 
Back to Top
kid_kaneda View Drop Down
Newbie
Newbie
Avatar

Joined: 28-Aug-2007
Posts: 6
Post Options Post Options   Quote kid_kaneda Quote  Post ReplyReply Direct Link To This Post 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?
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post 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.
 
Back to Top
kid_kaneda View Drop Down
Newbie
Newbie
Avatar

Joined: 28-Aug-2007
Posts: 6
Post Options Post Options   Quote kid_kaneda Quote  Post ReplyReply Direct Link To This Post 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.


Edited by kid_kaneda - 28-Aug-2007 at 4:18pm
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post 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.

Edited by davidklitzke - 28-Aug-2007 at 5:23pm
Back to Top
joshpainter View Drop Down
Newbie
Newbie
Avatar

Joined: 27-Aug-2007
Location: United States
Posts: 5
Post Options Post Options   Quote joshpainter Quote  Post ReplyReply Direct Link To This Post 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!
Back to Top
kid_kaneda View Drop Down
Newbie
Newbie
Avatar

Joined: 28-Aug-2007
Posts: 6
Post Options Post Options   Quote kid_kaneda Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down