locked
Linklabel in a DataGrid... RRS feed

  • Question

  • Hello All,

    I'm trying to add a link label in a column in a datagrid and am having a bit of trouble.

    I've found lots of samples for doing this in a winform application...but when I try and use it for mobile...it blows up.

    I've tried to run through and "convert" it to .netcf without any luck.

    Does anyone have a sample implementation of this for .netcf?

    .net cf 3.5
    wm 2003 se
    vs2008

    Thanks,
    Kevin
    Thursday, July 23, 2009 6:46 PM

Answers

  • You don't need any link labels in the grid. Just handle click event on the grid itself and see which cell it wall clicked in.
    You can also change the style of the text so it would look like link but that is optional.
    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by warrentang Monday, July 27, 2009 7:40 AM
    Friday, July 24, 2009 3:02 AM
  • You would need to override cell paining and draw text as blue and underlined.
    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by warrentang Monday, July 27, 2009 7:40 AM
    Friday, July 24, 2009 5:46 PM

All replies

  • Hi,

    The following forum posting should answer your question :-

    http://social.msdn.microsoft.com/Forums/en-US/vssmartdevicesvbcs/thread/6a2a6ce1-d779-466d-a52f-04468d00671a

    Please can you only ask your question in a single forum, it makes answering questions more difficult and can confuse others. It might be worth reading these guidelines :-

    http://www.danielmoth.com/Blog/2005/03/please-read-before-posting-to-ng.html

    Hope this helps.

    Paul Diston
    http://www.smartmobiledevice.co.uk/
    Thursday, July 23, 2009 6:54 PM
  • Hrm...I see all of his custom datagrid column styles.....too bad he didn't do one for a link.

    I'm trying to implement my own....and judging from his other styles...this would be all I need.

    public

     

    class DataGridLinkColumn : DataGridCustomColumnBase

    {

     

    public virtual LinkLabel LinkLabel

    {

     

    get { return this.HostedControl as LinkLabel; }

    }

     

    protected override string GetBoundPropertyName()

    {

     

    return "Click";

    }

     

    protected override Control CreateHostedControl()

    {

     

    LinkLabel linkLabel = new LinkLabel();

     

    return linkLabel;

    }
    }

    I'm not really sure where I'm suppose to actually place the linklabel for each row...

    dt.TableName =

    "OrdersTable";

    dt.Columns.Add(

    new DataColumn("Add"));

    LinkLabel

     

    label = new LinkLabel();

    label.Click +=

    new EventHandler(label_Click);

     

    DataRow dr = dt.NewRow();

    dr[

    "Add"] = label;

    DataGridTableStyle

     

    dgTableStyle = new DataGridTableStyle();

    dgTableStyle.MappingName = dt.TableName;

    DataGridLinkColumn

     

    dgLinkColumn = new DataGridLinkColumn();

     

    if (isOrders)

    dgLinkColumn.Owner =

    this.dgOrdersBoothListOS;

     

    else

    dgLinkColumn.Owner =

    this.dgFreightBoothListOS;

    dgLinkColumn.HeaderText =

    "Add";

    dgLinkColumn.MappingName =

    "Add";

    dgTableStyle.GridColumnStyles.Add(dgLinkColumn);

     

     

     



    What am I doing wrong?


    Thursday, July 23, 2009 7:48 PM
  • Eeek.  That code snippet didn't play nice.
    Thursday, July 23, 2009 7:50 PM
  • You don't need any link labels in the grid. Just handle click event on the grid itself and see which cell it wall clicked in.
    You can also change the style of the text so it would look like link but that is optional.
    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by warrentang Monday, July 27, 2009 7:40 AM
    Friday, July 24, 2009 3:02 AM
  • Hrm...that seems like the easiest approach...

    I actually woke up this morning with a similar thought, and what do ya know....

    Thanks dude!  I'll try it out today.
    Friday, July 24, 2009 3:09 PM
  • Dang....worked like a champ.

    Thanks!

    Friday, July 24, 2009 3:23 PM
  • Now the last piece of the puzzle....getting the text to show up as blue and underlined =)

    Thoughts?
    Friday, July 24, 2009 4:43 PM
  • DataRow

     

    dr = dt.NewRow();

     

    Font font = new Font("Arial", 8, FontStyle.Underline);

    dr[

    "Add"] = string.Format("Add", font);



    So that didn't work...

    Friday, July 24, 2009 4:55 PM
  • You would need to override cell paining and draw text as blue and underlined.
    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by warrentang Monday, July 27, 2009 7:40 AM
    Friday, July 24, 2009 5:46 PM