DataGridView -- What row am I on?

  • Thread starter Thread starter Dom
  • Start date Start date
D

Dom

I like to use the AlternateRow option for DataGridViews, so that the
odd rows have a defaut style, and the even rows have an alternate
style, usually just a light blue backcolor.

Sometimes I need to change the style of cell to give a visual clue
about the data, for example, italicise it. But (as far as I know), I
need to know which row I am on, so I can maintain the backcolor. Is
there something like a DataGridView1.Rows[0].IsAlternate property?

Dom
 
I like to use the AlternateRow option for DataGridViews, so that the
odd rows have a defaut style, and the even rows have an alternate
style, usually just a light blue backcolor.

Sometimes I need to change the style of cell to give a visual clue
about the data, for example, italicise it. But (as far as I know), I
need to know which row I am on, so I can maintain the backcolor. Is
there something like a DataGridView1.Rows[0].IsAlternate property?

It seems to me that if you wanted to know the row # of a given
DataGridViewCell, you could just look at the RowIndex property of the
cell. If you have the row itself then presumably you got it from
somewhere and could know the row # from that, but even if not you could
look at a cell in the rows cell collection and get a RowIndex from that.

But I'm not sure you need to do all of that. If you want to format a
DataGridViewCell as the same as its current format but changing just
one thing, why not get the current DataGridViewCellStyle of the cell
(InheritedStyle or Style, as appropriate), create a new one using that,
and change whatever part of the style you want, leaving the other style
components the same?

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top