Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I use these codes at OnCreateControl to add DataGridViewLinkColumn.
But I can't set text for column(not headerText, just text).
 
Note: When I add column by designer there is property named Text but inside below code it is not.
 
DataGridViewLinkCell cell = new DataGridViewLinkCell();
cell.UseColumnTextForLinkValue = true;
 
DataGridViewColumn column = new DataGridViewColumn();
column.CellTemplate = cell;
// column.Text dose not exists
this.Columns.Add(column);
Posted 29-Jul-12 8:01am
Comments
Kenneth Haugland at 29-Jul-12 14:13pm
   
column.Text wont exist but Column.Header might... The only field that would have a possible tetblock in it would be the DataGridViewLinkCell, so Ill bet you can find cell.text or?
Kenneth Haugland at 29-Jul-12 15:08pm
   
IT this WinForms or WPF?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Please revise if you see in designer the columns or rows. Columns haven't text, because they have differents data in each cell (normally). I can not found "text" in the designer, you can also only give the tooltip and header text.
 
If you want to have a default value in the column, you must create a derivated class from DataGridViewLinkCell and override the DefaultNewRowValue
 
see the following example (dirty example, you should create a new file for the derived class):
 
 
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            DataGridViewLinkCell cell = new NewDataGridViewLinkCell();
            cell.UseColumnTextForLinkValue = true;
            
            DataGridViewColumn column = new DataGridViewColumn();
           column.CellTemplate = cell;
 
            // column.Text dose not exists
            dataGridView1.Columns.Add(column);
            dataGridView1.Rows.Add(new DataGridViewRow());
            
        }
    }
 
    public class NewDataGridViewLinkCell : DataGridViewLinkCell
    {
        public override object DefaultNewRowValue
        {
            get
            {
                // Enter here your text.
                return "My Text";
            }
        }
 
    }
 
Observe that now, you instance NewDataGridViewLinkCell and you can enter a predefined test each time that a new row is created.
  Permalink  
Comments
freedeveloper at 1-Aug-12 23:54pm
   
When you run this code you dont see the "My Text" in column? To enter a URL link, you must enter a URL link, and override the DefaultNewRowValue as a url.
You can see more information at: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.defaultnewrowvalue.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 328
1 Sergey Alexandrovich Kryukov 295
2 Gihan Liyanage 292
3 ClimerChinna 232
4 Abhinav S 192
0 Sergey Alexandrovich Kryukov 8,213
1 OriginalGriff 7,089
2 CPallini 2,598
3 Richard MacCutchan 1,925
4 Abhinav S 1,778


Advertise | Privacy | Mobile
Web01 | 2.8.140826.1 | Last Updated 1 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100