How To Dynamically Update KryptonDataGridViewTextAndImageColumn Text And Image

Jul 14, 2013 at 3:13 PM
Edited Jul 14, 2013 at 3:30 PM
I have a KryptonDataGridViewTextAndImageColumn that only has an image in it. I want to have a mouse enter leave effect on my grid that hides/shows the image when the mouse leaves/enters a row.

How would I go about doing this???

Secon question:

How do I capture click events on the KryptonDataGridViewTextAndImageCell???
Jul 14, 2013 at 9:31 PM
This is what I have done so far

It seems to work when I'm looking at the code, that is. It does update the cell values as needed. But the grid does not show the changes. Is there a way of refreshing the cell to show changes.
private void dgv_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
        {
            int rowIndex = e.RowIndex;
            //int colIndex = e.ColumnIndex;

            if (rowIndex < 0 || rowIndex >= this.Rows.Count)
            {
                return;
            }

            foreach (DataGridViewColumn dgvc in this.Columns)
            {
                if (this[dgvc.Index, rowIndex].OwningColumn.GetType() == typeof(KryptonDataGridViewTextAndImageColumn) && !((OutlookGridRow)this.Rows[rowIndex]).IsGroupRow)
                {
                    this[dgvc.Index, rowIndex].Value = new TextAndImage(string.Empty, ((KryptonDataGridViewTextAndImageColumn)this[dgvc.Index, rowIndex].OwningColumn).Image);
                }
            }
        }

        private void dgv_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
        {
            int rowIndex = e.RowIndex;
            //int colIndex = e.ColumnIndex;

            if (rowIndex < 0 || rowIndex >= this.Rows.Count)
            {
                return;
            }

            foreach (DataGridViewColumn dgvc in this.Columns)
            {
                if (this[dgvc.Index, rowIndex].OwningColumn.GetType() == typeof(KryptonDataGridViewTextAndImageColumn) && !((OutlookGridRow)this.Rows[rowIndex]).IsGroupRow)
                {
                    this[dgvc.Index, rowIndex].Value = new TextAndImage(string.Empty, null);
                }
            }
        }
Coordinator
Jul 14, 2013 at 10:29 PM
Hi,

This codes should work at least if you add a picture to the column.
   private void OutlookGrid1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
        {
            int rowIndex = e.RowIndex;
            //int colIndex = e.ColumnIndex;

            if (rowIndex < 0 || rowIndex >= this.OutlookGrid1.Rows.Count)
            {
                return;
            }

            if (OutlookGrid1.Columns[e.ColumnIndex] is KryptonDataGridViewTextAndImageColumn && !((OutlookGridRow)this.OutlookGrid1.Rows[e.RowIndex]).IsGroupRow)
            {
                OutlookGrid1[e.ColumnIndex, e.RowIndex].Value = new TextAndImage(string.Empty, ((KryptonDataGridViewTextAndImageColumn)OutlookGrid1[e.ColumnIndex, e.RowIndex].OwningColumn).Image);
                }
        }

        private void OutlookGrid1_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
        {
            int rowIndex = e.RowIndex;
            //int colIndex = e.ColumnIndex;

            if (rowIndex < 0 || rowIndex >= this.OutlookGrid1.Rows.Count)
            {
                return;
            }

            if (OutlookGrid1.Columns[e.ColumnIndex] is KryptonDataGridViewTextAndImageColumn && !((OutlookGridRow)this.OutlookGrid1.Rows[e.RowIndex]).IsGroupRow)
            {
                OutlookGrid1[e.ColumnIndex, e.RowIndex].Value = new TextAndImage(string.Empty, null);
            }
        }
May I ask why you are using the TextAndImage Column with not text ? For displaying image only there is the DataGridViewImageColumn ?
Jul 15, 2013 at 11:16 AM
Edited Jul 15, 2013 at 11:17 AM
Ok. Thanx... I swtiched to a DataGridViewImageColumn and getting the results I wanted.