winforms - .NET DataGridView: Remove "current row" black triangle -


in datagridview, if set grid readonly there black triangle @ rows headers shown @ current row.

i'd avoid shown, i'd avoid big padding of cells caused triangle. guess padding caused triangle because cell's padding 0.

is posible that? how?

thanks!

edit

this how row headers text created:

for (int = 0; < 5; i++) {     datagridviewrow row = new datagridviewrow();     row.headercell.value = headers[i];     datagridview1.rows.add(row); } 

and headers array of strings. (string[])

  • if want keep row headers rather hide them, can use cell padding push triangle out of sight:

    this.datagridview1.rowheadersdefaultcellstyle.padding =      new padding(this.datagridview1.rowheaderswidth); 
  • if using row header text , want keep visible need use custom painting - thankfully simple. after above code, attach rowpostpaint event shown below:

    datagridview1.rowpostpaint +=      new datagridviewrowpostpainteventhandler(datagridview1_rowpostpaint); 

    and in rowpostpaint method:

    void datagridview1_rowpostpaint(object sender, datagridviewrowpostpainteventargs e) {     object o = datagridview1.rows[e.rowindex].headercell.value;      e.graphics.drawstring(         o != null ? o.tostring() : "",         datagridview1.font,          brushes.black,          new pointf((float)e.rowbounds.left + 2, (float)e.rowbounds.top + 4)); } 

    as dan neely points out use of brushes.black above overwrite existing changes, better brush use:

    new solidbrush(datagridview1.rowheadersdefaultcellstyle.forecolor) 

Comments

Popular posts from this blog

Python __call__ special method practical example -

How can I edit my VIM config so that Vim treats ".ejs" files the same as it currently treats my html files? -