private void dataGridView1_CellToolTipTextNeeded(object sender, DataGridViewCellToolTipTextNeededEventArgs e)
{
if (e.ColumnIndex == -1 || e.RowIndex == -1 || e.RowIndex >= m_dataTable.Rows.Count)
return;
ulong val = 0;
Type dataType = m_dataTable.Columns[e.ColumnIndex].DataType;
CultureInfo culture = CultureInfo.InvariantCulture;
object value = dataGridView1[e.ColumnIndex, e.RowIndex].Value;
if (dataType != typeof(string))
{
if (dataType == typeof(sbyte))
val = (ulong)Convert.ToSByte(value, culture);
else if (dataType == typeof(byte))
val = Convert.ToByte(value, culture);
else if (dataType == typeof(short))
val = (ulong)Convert.ToInt16(value, culture);
else if (dataType == typeof(ushort))
val = Convert.ToUInt16(value, culture);
else if (dataType == typeof(int))
val = (ulong)Convert.ToInt32(value, culture);
else if (dataType == typeof(uint))
val = Convert.ToUInt32(value, culture);
else if (dataType == typeof(long))
val = (ulong)Convert.ToInt64(value, culture);
else if (dataType == typeof(ulong))
val = Convert.ToUInt64(value, culture);
else if (dataType == typeof(float))
val = BitConverter.ToUInt32(BitConverter.GetBytes((float)value), 0);
else if (dataType == typeof(double))
val = BitConverter.ToUInt64(BitConverter.GetBytes((double)value), 0);
else
val = Convert.ToUInt32(value, culture);
}
else
{
if (m_dbreader.StringTable != null)
val = (uint)m_dbreader.StringTable.Where(kv => string.Compare(kv.Value, (string)value, StringComparison.Ordinal) == 0).Select(kv => kv.Key).FirstOrDefault();
}
StringBuilder sb = new StringBuilder();
sb.AppendFormatLine(culture, "Integer: {0:D}", val);
sb.AppendFormatLine(new BinaryFormatter(), "HEX: {0:X}", val);
sb.AppendFormatLine(new BinaryFormatter(), "BIN: {0:B}", val);
sb.AppendFormatLine(culture, "Float: {0}", BitConverter.ToSingle(BitConverter.GetBytes(val), 0));
sb.AppendFormatLine(culture, "Double: {0}", BitConverter.ToDouble(BitConverter.GetBytes(val), 0));
string strValue;
if (m_dbreader.StringTable != null && m_dbreader.StringTable.TryGetValue((int)val, out strValue))
{
sb.AppendFormatLine(culture, "String: {0}", strValue);
}
else
{
sb.AppendFormatLine(culture, "String: <empty>");
}
e.ToolTipText = sb.ToString();
}