Click here to Skip to main content
15,911,848 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all, I have a DataGridView binded to a DataTable.
I want to insert a DataGridViewLinkColumn not binded to a Datatable's field but I'm not able to display different values in that column's cells.

If I set UseColumnTextForLinkValue = true it displays the same value in each cell (the value I specified in Text property).

If I set UseColumnTextForLinkValue = false it displays nothing even though I set my own values in each cell.

What should I do to display different values?

TIA.
Alder
Posted
Comments
[no name] 16-Jan-13 9:45am    
Your question is not so clear. Please elaborate more...
ALDER_MORIGGI 16-Jan-13 9:59am    
I've linked my DataGridView to a DataSource.
After I've added a new column (a DataGridViewLinkColumn) not included in the Datasource, I want to write different links in that column, but I can't.
If I specify UseColumnTextForLinkValue = true in the cell's column appears the same value; If I specify UseColumnTextForLinkValue = false in the cell's column appears no value.

Below my code:

DataGridViewLinkColumn l_Warning_Agente = new DataGridViewLinkColumn();
l_Warning_Agente.Name = WARNING_COLUMN_NAME;
l_Warning_Agente.HeaderText = "Warning Agent";
l_Warning_Agente.Width = 100;
l_Warning_Agente.ReadOnly = false;
l_Warning_Agente.FillWeight = 10;
l_Warning_Agente.ValueType = Type.GetType("System.String");
l_Warning_Agente.UseColumnTextForLinkValue = true;
//l_Warning_Agente.DataPropertyName = ObjSimPaz.CAMPO_AGENTE_DESCRIZIONE_AGENTIPROPOSTA_TSP24;
l_Warning_Agente.Text = "Warning";
l_Warning_Agente.LinkBehavior = LinkBehavior.SystemDefault;
l_Warning_Agente.LinkColor = Color.Blue;
l_Warning_Agente.TrackVisitedState = true;
dgvTable.Columns.Add(l_Warning_Agente);

foreach (DataGridViewRow dRow in dgvTable.Rows)
{
dRow.Cells["SP24_WARNING"].Value = "
}

I've solved my question. I set different values in DataGridViewLinkColumn in the form's load event. It was my fault...
 
Share this answer
 
Comments
vidkaat 6-Aug-13 15:08pm    
I am facing a similar problem. Can you please help me out .
Keerthi Koneru 12-May-15 14:20pm    
Hi Alder,
I am facing the same issue and i could not understand your answer. Can you please help me out??
Hello,

You can add TableCell by implementing the handler of a GridView RowDataBound event.

For example:

C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                TableCell newcell = new TableCell();
                newcell.Text = "123";
                e.Row.Cells.Add(newcell);
            }
        }


To access cells in specific columns use this example:

C#
string Contract = DataBinder.Eval(e.Row.DataItem, "Contract").ToString();


Hope it helps.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900