Loogawa
Loogawa

Reputation: 389

Is it possible to set vb.net datagridview cell alignment without modifying whole column?

I am trying to set the alignment of a specific cell in a row/column to be right aligned. However I do not want to set the whole row, or whole column to right aligned. Is it possible to set the cell only? From what I've seen online I'm starting to think it isn't possible.

Upvotes: 0

Views: 304

Answers (1)

Mych
Mych

Reputation: 2553

You would need to hook up to the RowDataBound event. This fires as each row is databound. Check that the row is a data row (as opposed to a header or footer). Then check the value in the column you are interested in. If the value meets your criteria for right justification then apply that to the column in question.

Note if you are using AlternateItemTemplate then check both Item rows and AlternateItem rows.

I've used this method to say change the backround colour of values that fall outside a range.

Upvotes: 1

Related Questions