Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The default style for the row header should already be defined when you build your <code>DataGridView</code>. So I would use:</p> <pre><code>if ( /*I want to change this row */) { DataGridViewCellStyle rowStyle; // = Grid.RowHeadersDefaultCellStyle; rowStyle = Grid.Rows[i].HeaderCell.Style; rowStyle.BackColor = Color.Wheat; Grid.Rows[i].HeaderCell.Style = rowStyle; } </code></pre> <p>This way you fill your <code>rowStyle</code> with the predefined style and then change only the part you want to change. See if this solves your problem.</p> <p>//EDIT As you wish to keep the other stylings of the default Windows DataGridView, you would also need to set more of the other parameters of the style. See <a href="http://www.codeproject.com/Questions/164629/How-to-change-only-DataGridView-RowHeader-s-Grid-C" rel="nofollow noreferrer">this post.</a></p> <p>Or try this. When initialiazing:</p> <pre><code> dataGridView1.CellPainting += new DataGridViewCellPaintingEventHandler (dataGridView_CellPainting); </code></pre> <p>Then create the handler function with something like:</p> <pre><code> void dataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { DataGridView dv = sender as DataGridView; DataGridViewCellStyle rowStyle;// = dv.RowHeadersDefaultCellStyle; if (e.ColumnIndex == -1) { e.PaintBackground(e.CellBounds, true); e.Handled = true; if (/*I want to change this row */) { rowStyle = dv.Rows[e.RowIndex].HeaderCell.Style; rowStyle.BackColor = Color.Wheat; dv.Rows[e.RowIndex].HeaderCell.Style = rowStyle; using (Brush gridBrush = new SolidBrush(Color.Wheat)) { using (Brush backColorBrush = new SolidBrush(e.CellStyle.BackColor)) { using (Pen gridLinePen = new Pen(gridBrush)) { // Clear cell e.Graphics.FillRectangle(backColorBrush, e.CellBounds); //Bottom line drawing e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom - 1, e.CellBounds.Right, e.CellBounds.Bottom - 1); // here you force paint of content e.PaintContent(e.ClipBounds); e.Handled = true; } } } } } } </code></pre> <p>This code was based on <a href="https://stackoverflow.com/questions/6041044/how-to-paint-only-datagridviews-cell-background-not-its-content">this post.</a> You would only then need to create more paint conditions for mouseover and selected state. But this should work for you.</p> <p>Remember to remove: <code>Grid.EnableHeadersVisualStyles = false;</code> or force it to: <code>Grid.EnableHeadersVisualStyles = true;</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload