Bollwerk

Is there a way to show a ToolTip when the user hovers over a RowHeader in a DataGridView I'm coding in VC++/CLI in VS2005.

Thanks



Re: Windows Forms Data Controls and Databinding RowHeader ToolTip

Gavin Jin - MSFT

HiŁ¬ I am not familar with VC++,but you can set row header tooltip in this way.

dataGridView1.Rows[0].HeaderCell.ToolTipText = "Row Header ToolTip";

please check this article

http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.tooltiptext.aspx

there is a sample code in VC++

Hope it helps

Regards






Re: Windows Forms Data Controls and Databinding RowHeader ToolTip

Bollwerk

That's what I thought was the solution and it works for a normal DataGridView (DGV) control. However, I'm using a derived DGV and now it looks like ToolTips isn't working in it. I override the OnEditingControlShowing and ProcessKeyPreview methods, should that cause the problem I also create some column classes that allow me to have mumeric, decimal, and time columns in the DGV. This is my first experience with deriving a control so I'm probably missing something. (Yes I have the DGV.ShowCellToolTips = true). Here is the code, I'd appreciate any help:

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace DGV_Derived1
{
public class dgv : System.Windows.Forms.DataGridView
{
public
int colIndx;
bool backspace;
DataGridViewColumn dgvCol;
Type colType;
String sType;

public dgv()
{

}

#region Code for Numeric, Decimal & Time Columm types
//Decimal Column Class - integer numbers only
public class DecimalColumn : System.Windows.Forms.DataGridViewTextBoxColumn
{
public DecimalColumn()
{
this.CellTemplate = new DataGridViewTextBoxCell();
}
}

//Numeric Column Class - integer numbers only
public class NumericColumn : System.Windows.Forms.DataGridViewTextBoxColumn
{
public NumericColumn()
{
this.CellTemplate = new DataGridViewTextBoxCell();
}
}

//Time Column Class - integer numbers and a colon 12:59 for example
public class TimeColumn : System.Windows.Forms.DataGridViewTextBoxColumn
{
public TimeColumn()
{
this.CellTemplate = new DataGridViewTextBoxCell();
}
}

void NumericKeyPress(Object sender, KeyPressEventArgs e)
{
String alpha = "0123456789";
if (backspace) { return; }
if (alpha.IndexOf(e.KeyChar) == -1) { e.Handled = true; }
}

void DecimalKeyPress(Object sender, KeyPressEventArgs e)
{
String alpha = "0123456789.";
if (backspace) { return; }
if (alpha.IndexOf(e.KeyChar) == -1) { e.Handled = true; }
}

void TimeKeyPress(Object sender, KeyPressEventArgs e)
{
String alpha = "0123456789:";
if (backspace) { return; }
if (alpha.IndexOf(e.KeyChar) == -1) { e.Handled = true; }
}
//This is needed to get the Backspace key to work in a custom column
void TextEditKeyDown(object sender, KeyEventArgs e)
{
backspace = false;
if (e.KeyCode == Keys.Back) {backspace = true;}
}

protected override void OnEditingControlShowing(System.Windows.Forms.DataGridViewEditingControlShowingEventArgs e)
{
colIndx = this.CurrentCell.ColumnIndex;
dgvCol = this.Columns[colIndx];
colType = dgvCol.GetType();
sType = colType.ToString();

if (! sType.Equals("DGV_Derived1.dgv+NumericColumn") &&
! sType.Equals("DGV_Derived1.dgv+DecimalColumn") &&
! sType.Equals("DGV_Derived1.dgv+TimeColumn"))
{ base.OnEditingControlShowing(e); return; }

TextBox tb = (TextBox)e.Control;
//Get rid of any existing event handlers
tb.KeyPress -= new KeyPressEventHandler(NumericKeyPress);
tb.KeyPress -= new KeyPressEventHandler(DecimalKeyPress);
tb.KeyPress -= new KeyPressEventHandler(TimeKeyPress);
tb.KeyDown -= new KeyEventHandler(TextEditKeyDown);
if (sType.Equals("DGV_Derived1.dgv+NumericColumn"))
{
tb.KeyPress += new KeyPressEventHandler(NumericKeyPress);
tb.KeyDown += new KeyEventHandler(TextEditKeyDown);
}
else if (sType.Equals("DGV_Derived1.dgv+DecimalColumn"))
{
tb.KeyPress += new KeyPressEventHandler(DecimalKeyPress);
tb.KeyDown += new KeyEventHandler(TextEditKeyDown);
}
else if (sType.Equals("DGV_Derived1.dgv+TimeColumn"))
{
tb.KeyPress += new KeyPressEventHandler(TimeKeyPress);
tb.KeyDown += new KeyEventHandler(TextEditKeyDown);
}
base.OnEditingControlShowing(e);
}

protected override bool ProcessKeyPreview(ref Message m)
{

KeyEventArgs args1 = new KeyEventArgs(((Keys)((int)m.WParam)) | Control.ModifierKeys);

switch (args1.KeyCode)
{
case Keys.Left:
case Keys.Right:
case Keys.Up:
case Keys.Down:
case Keys.Home:
case Keys.End:
case Keys.Insert:
case Keys.Delete:
case Keys.Back:
return false;

}
return base.ProcessKeyPreview(ref m);
}
#endregion

}

}





Re: Windows Forms Data Controls and Databinding RowHeader ToolTip

Bollwerk

A similar question, How do I get ToolTips to work on the RowHeader when the DataGridView's DataSource is set to a DataTable Setting the HeaderCellToolTipText doesn't work in this case.

Thanks