views:

198

answers:

1

Hi there,

I am asking this question here as I could not find any conclusive results thru Google. HOw would it be possible to include an image and text in the same column in a Winforms datagridview?

I have the following code handling the CellPainting event, but it does not work too well if the user adjusts the height of the row.

private void dgvTasks_CellPainting( object sender, DataGridViewCellPaintingEventArgs e ) {
    if (e.RowIndex >= 0 && e.ColumnIndex == 7) {
        e.Graphics.DrawImage( Properties.Resources.task, e.CellBounds.X, e.CellBounds.Y, 16, 16 );
    }
    e.Handled = true;
}

Column 7 is currently databound to a string type. As mentioned, the problem with the above code, is that when the user resizes the row height, the text automatically vertically aligns to the center, but the image stays put in the top-left.

I started creating my own DataGridViewImageTextColumn (and Cell) class that inherits from DataGridViewColumn/Cell, but dont know how to take this idea further. Is it any way possible for someone to help me out on this one by giving me a nudge in the right direction?

Forever grateful!

Cheers!

A: 

nevermind...its too much of a bother. I just disabled row-resizing

Shalan