You are on page 1of 10

Formatting link column datagridview not working?

1 of 10

http://www.experts-exchange.com/Programming/Languages/.NET/Q_249...

.NET Question
Formatting link column datagridview
not working?
Asked by: arcross on 11-19-2009
Solved by: jpaulino

Hello,
ive got a datagridview (dgv) and one of its columns is a
LinkColumn. What im doing is changing the color of the text, for
that column, when certain conditions apply. But the forecolor

+ Expand to see the entire question

Veri ed Solution
jpaulino 2009-11-19 at 12:34:02 ID: 25864617

Check this small example:


1:
2:
3:
4:
5:
6:
7:
8:

Private Sub DataGridView1_CellFormatting(ByVal sender


If e.ColumnIndex = 1 Then
If Me.DataGridView1(1, e.RowIndex).Value = "12
Dim lnk As DataGridViewLinkCell = DirectCa
lnk.LinkColor = Color.Black
End If
End If
End Sub

Jump to view entire expert comment thread


Select all

Open in new window

12/4/2014 3:06 PM

Formatting link column datagridview not working?

2 of 10

http://www.experts-exchange.com/Programming/Languages/.NET/Q_249...

Questions? Call us:


Browse Topics

Solve your
tech
How
Itproblems
Works faster

1-877-211-8911

Mon-Fri> Programming
5AM-8PM
PST
> Prog Languages

Experts Exchange

Try It Free

Join Today

> .NET Programming

Login

> Formatting link column datagridview not working

30 Day free trial.

Trusted by Thousands of Top Companies

View All Expert Comments in Order:

Expert Comment
CodeCruiser 2009-11-19 at 08:52:32 ID: 25862266

The foreground color for Links is determined by


CSS and blue is used otherwise.
Was this the answer you needed?

12/4/2014 3:06 PM

Formatting link column datagridview not working?

3 of 10

http://www.experts-exchange.com/Programming/Languages/.NET/Q_249...

Questions? Call us:


Browse Topics

Solve your
tech
How
Itproblems
Works faster

1-877-211-8911

Mon-Fri> Programming
5AM-8PM
PST
> Prog Languages

Experts Exchange

Join Today

> .NET Programming

Login

> Formatting link column datagridview not working

Expert Comment
CodeCruiser 2009-11-19 at 09:06:29 ID: 25862465

>im using a datagridview with vb.net


VB.NET is also used in ASP.NET but yes i was
talking about ASP.NET.
I am not sure if it would help but give it a try
http://stackover ow.com/questions/586829/chan
ge-color-of-button-in-datagridview-cell

Veri ed Solution
jpaulino 2009-11-19 at 12:34:02 ID: 25864617

Check this small example:


1:
2:
3:
4:
5:
6:
7:
8:

Private Sub DataGridView1_CellFormatting(ByVal sender


If e.ColumnIndex = 1 Then
If Me.DataGridView1(1, e.RowIndex).Value = "12
Dim lnk As DataGridViewLinkCell = DirectCa
lnk.LinkColor = Color.Black
End If
End If
End Sub

Was this the answer you needed?

12/4/2014 3:06 PM

Formatting link column datagridview not working?

4 of 10

http://www.experts-exchange.com/Programming/Languages/.NET/Q_249...

Questions? Call us:


Browse Topics

Solve your
tech
How
Itproblems
Works faster

1-877-211-8911

Mon-Fri> Programming
5AM-8PM
PST
> Prog Languages

Experts Exchange

Join Today

> .NET Programming

Login

> Formatting link column datagridview not working

Expert Comment
trideep 2009-11-19 at 22:33:50 ID: 25868002

Try to add this code in you cellformatting event


If e.ColumnIndex = 1 Then 'Replace with ur link
column index
Dim lcell As DataGridViewLinkCell =
Me.DataGridView1.Rows(e.RowIndex).Cells("Defau
lt")
'''Add logic/ Condition to set color
lcell.LinkColor = Color.Brown
End If

Was this the answer you needed?

12/4/2014 3:06 PM

Formatting link column datagridview not working?

5 of 10

http://www.experts-exchange.com/Programming/Languages/.NET/Q_249...

Questions? Call us:


Browse Topics

Solve your
tech
How
Itproblems
Works faster

1-877-211-8911

Mon-Fri> Programming
5AM-8PM
PST
> Prog Languages

Experts Exchange

2:
3:
4:
5:
6:
7:
8:
9:

Join Today

> .NET Programming

Login

> Formatting link column datagridview not working

If Me.DataGridView1.Columns(e.ColumnIndex).Name =
If Me.DataGridView1.Item("Id", e.RowIndex).Val
Dim lnk As DataGridViewLinkCell = CType(Me
lnk.LinkColor = Color.Green
MsgBox(Me.DataGridView1.Item(1, e.RowIndex
End If
End If
End Sub

Expert Comment
jpaulino 2009-11-19 at 23:32:15 ID: 25868174

Humm, don't you guys saw my post before ? I

Expert Comment
roma2208 2009-11-19 at 23:35:23 ID: 25868184

Your code is giving error to me...


Unable to cast object of type
'System.Windows.Forms.DataGridViewTe
xtBoxCell' to type 'System.Windows.Forms.Data
GridViewLinkCell'.
Was this the answer you needed?

12/4/2014 3:06 PM

Formatting link column datagridview not working?

6 of 10

http://www.experts-exchange.com/Programming/Languages/.NET/Q_249...

Questions? Call us:


Browse Topics

Solve your
tech
How
Itproblems
Works faster

1-877-211-8911

Mon-Fri> Programming
5AM-8PM
PST
> Prog Languages

Experts Exchange

Join Today

> .NET Programming

Login

> Formatting link column datagridview not working

Expert Comment
jpaulino 2009-11-19 at 23:40:38 ID: 25868209

That's because my DataGridViewLinkCell is in


column 2 (index 1) and not in the rst one (index
0)
DirectCast(Me.DataGridView1(1, e.RowIndex),
DataGridViewLinkCell)
I always test my code! ;)

Expert Comment
roma2208 2009-11-19 at 23:44:17 ID: 25868221

Oh.. yes this may be the case why i m getting this


error. Sorry for error posted... :)

Expert Comment
jpaulino 2009-11-19 at 23:48:33 ID: 25868240

Was this the answer you needed?

12/4/2014 3:06 PM

Formatting link column datagridview not working?

7 of 10

http://www.experts-exchange.com/Programming/Languages/.NET/Q_249...

Questions? Call us:


Browse Topics

Solve your
tech
How
Itproblems
Works faster

1-877-211-8911

Mon-Fri> Programming
5AM-8PM
PST
> Prog Languages

Experts Exchange

Join Today

> .NET Programming

Login

> Formatting link column datagridview not working

Thanks everyone!

Ask .NET Experts Your Technical


Questions
for One-on-One Help

30 Day free trial.

Trusted by Thousands of Top Companies

Was this the answer you needed?

12/4/2014 3:06 PM

Formatting link column datagridview not working?

8 of 10

http://www.experts-exchange.com/Programming/Languages/.NET/Q_249...

Questions? Call us:


Browse Topics

Solve your
tech
How
Itproblems
Works faster

1-877-211-8911

Mon-Fri> Programming
5AM-8PM
PST
> Prog Languages

Experts Exchange

1.

Join Today

> .NET Programming

Login

> Formatting link column datagridview not working

Import Rows between 2 datasets for all tables with matching


columns

2.

Crystal Reports work on local machine but when I upload to


cloud server it does not work. VS2010

3.

VB.net Datatable -> check if column contains value before adding


it

4.

Datagridview column problem

5.

Calculating column datagridview

6.

Capture value from combo box column in datagridview

7.

Change height of combobox column in datagridview

8.

gridview column is null asp.net 4.0


Was this the answer you needed?

12/4/2014 3:06 PM

Formatting link column datagridview not working?

9 of 10

http://www.experts-exchange.com/Programming/Languages/.NET/Q_249...

Questions? Call us:


Browse Topics

Solve your
tech
How
Itproblems
Works faster

1-877-211-8911

Mon-Fri> Programming
5AM-8PM
PST
> Prog Languages

Experts Exchange

several

Join Today

> .NET Programming

Login

> Formatting link column datagridview not working

14.

"Index was out of range" DataGridView End User Only Error

15.

ASP.Net Datalist Control 'RepeatDirection' not working in Firefox


See More .NET Solutions

201410-LO-Qu-022

1. How to format particular

column records of
datagridview to mm:ss format
in VB.NET ?
2. DataGridView Number format

and sizing of column


3. Link Button in Gridview

Template Column
4. DataGridView - unable to

change column widths in


Design Mode or Runtime
5. vb datagridview with unbound

column
6. Datagridview column running

Was this the answer you needed?

12/4/2014 3:06 PM

Formatting link column datagridview not working?

10 of 10

http://www.experts-exchange.com/Programming/Languages/.NET/Q_249...

Questions? Call us:


Browse Topics

Solve your
tech
How
Itproblems
Works faster

1-877-211-8911

Mon-Fri> Programming
5AM-8PM
PST
> Prog Languages

Experts Exchange

How It works

Join Today

> .NET Programming

Login

> Formatting link column datagridview not working

For Business

Solve Your Difficult Tech Problems


Solve

Plans and

Faster with Experts Exchange

Learn

Pricing

Resource
Network
Access millions of veri ed solutions and get
Library
1-on-1 help from the experts.

About Experts Exchange


Who We Are

freeContact
30 Day
trial.

The Experts

Blog

Us

Careers

Privacy Policy Terms of Use Help Site Map


1996-2014 Experts Exchange, LLC. All rights reserved. Covered by US Patent.

Was this the answer you needed?

Mobile Site

12/4/2014 3:06 PM

You might also like