Resolved DataGridView SelectedCells not getting set.

tim8w

Well-known member
Joined
Sep 8, 2020
Messages
130
Programming Experience
10+
Hi,
I have a DataGrdiView that has rows that are multi-line. I have Wrap turned ON and that works fine. The problem is that when I click on a cell, SelectedCells is not getting set and the SeelctedBaclColor and SelectedForeColor are not being set. I've been all over the settings for the DataGridView and for the life of me I cannot see anything that would be causing this. I have other DataGridViews in other programs which work fine and when I compare all the DatagGridView settings, I can not find anything that is different in the one that works compared to the one that doesn't. Any ideas where to concentrate on to find the problem?
 
By any chance did you override the WndProc of the DataGridView? Or did you implement some event handlers for cell click, cell enter and not follow the correct protocol for handling the event?
 
By any chance did you override the WndProc of the DataGridView? Or did you implement some event handlers for cell click, cell enter and not follow the correct protocol for handling the event?
No. The only Event I am processing is CellMouseEnter() and CellMouseLeave() so I can show/remove a custom Tooltip and CellMouseClick() so I can allow the user to copy the cell contents. I don't have custom tooltips in the other programs. Could it be the CellMouseEnter and Leave are affecting CellMouseClick?

C#:
        private void dgvProduction_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                if (dgvProduction[e.ColumnIndex, e.RowIndex].ToolTipText.Length > 0)
                {
                    tooltip = new frmCustomToolTip();
                    tooltip.ToolTipText = dgvProduction[e.ColumnIndex, e.RowIndex].ToolTipText.ToString();
                    tooltip.StartPosition = FormStartPosition.Manual;
                    tooltip.Location = new Point(this.Location.X + dgvProduction.Location.X + dgvProduction.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Location.X + 15, this.Location.Y + dgvProduction.Location.Y + dgvProduction.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Location.Y + dgvProduction.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Height / 2);
                    tooltip.Show();
                }
            }
        }

        private void dgvProduction_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
        {
            if (tooltip != null)
            {
                tooltip.Close();
                tooltip = null;
            }
        }
 
No. The only Event I am processing is CellMouseEnter() and CellMouseLeave() so I can show/remove a custom Tooltip and CellMouseClick() so I can allow the user to copy the cell contents. I don't have custom tooltips in the other programs. Could it be the CellMouseEnter and Leave are affecting CellMouseClick?

C#:
        private void dgvProduction_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                if (dgvProduction[e.ColumnIndex, e.RowIndex].ToolTipText.Length > 0)
                {
                    tooltip = new frmCustomToolTip();
                    tooltip.ToolTipText = dgvProduction[e.ColumnIndex, e.RowIndex].ToolTipText.ToString();
                    tooltip.StartPosition = FormStartPosition.Manual;
                    tooltip.Location = new Point(this.Location.X + dgvProduction.Location.X + dgvProduction.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Location.X + 15, this.Location.Y + dgvProduction.Location.Y + dgvProduction.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Location.Y + dgvProduction.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Height / 2);
                    tooltip.Show();
                }
            }
        }

        private void dgvProduction_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
        {
            if (tooltip != null)
            {
                tooltip.Close();
                tooltip = null;
            }
        }
I forgot that originally they did not want the Selection shown. I missed the Event SelectionChanged() in which I was clearing the selection. Thanks for the help...
 
Back
Top Bottom