vb.net
vb.net

Reputation: 11

underline in datagridview

I want to underline all items in one column. My code does not work.

dgv.Columns(5).DefaultCellStyle.Font.Underline()

thanks.

Upvotes: 1

Views: 6428

Answers (4)

jase
jase

Reputation: 237

If you are using C#, use this.

dataGridView1.Columns[0].DefaultCellStyle.Font = new Font(dataGridView1.DefaultCellStyle.Font, FontStyle.Underline);

Upvotes: 0

Mehrdad
Mehrdad

Reputation: 2116

You should set the style as:

dgv.Columns[5].DefaultCellStyle.Font = New Font(dgv.DefaultCellStyle.Font, FontStyle.Underline)

Upvotes: 1

MatiasMarturet
MatiasMarturet

Reputation: 1

I think you should do it for each row. For example: For Each r As DataGridViewRow In dgv.Rows r.Cells(5).Style.Font = New Font(dgv.DefaultCellStyle.Font, FontStyle.Underline) Next

Upvotes: 0

Jonathan
Jonathan

Reputation: 1507

Are you setting that property before or after inserting a value into the cell? I am not 100% sure, but, if memory serves, this will not change the style retroactively.

Looking at http://msdn.microsoft.com/en-us/library/system.drawing.font_members.aspx, it seems that Underline() is just a property that tells you if it's underlined. In C#, you might do

dgv.Columns(5).DefaultCellStyle.Font = new Font(dgv.Columns(5).DefaultCellStyle.Font, FontStyle.Underline);

but I don't know the VB syntax offhand.

Upvotes: 2

Related Questions