如果在一个DataGridView里面嵌套一个Datagridview?

boredom_vc 2007-04-20 05:33:56
如果在一个DataGridView里面嵌套一个Datagridview?

或者这样:
当用户先定某一行,我想显示一个图像的ToolTip,这个如何实现?
...全文
1157 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lnwuyaowei 2007-04-23
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace Loadometer.ClassExp
{
public class CalendarColumn : DataGridViewColumn
{

private bool showUpDown = true;

public bool ShowUpDown
{
get
{
return showUpDown;
}
set
{
showUpDown = value;
}
}

public CalendarColumn()
: base(new CalendarCell())
{
}

public override DataGridViewCell CellTemplate
{
get
{
return base.CellTemplate;
}
set
{

if (value != null &&
!value.GetType().IsAssignableFrom(typeof(CalendarCell)))
{
throw new InvalidCastException("Must be a CalendarCell");
}
base.CellTemplate = value;
}
}

private void InitializeComponent()
{

}
}
public class CalendarCell : DataGridViewTextBoxCell
{
public CalendarCell()
: base()
{

}

public override void InitializeEditingControl(int rowIndex, object
initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
{


base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle);
CalendarEditingControl ctl =
DataGridView.EditingControl as CalendarEditingControl;
ctl.Text = this.Value.ToString();

}

public override Type EditType
{
get
{

return typeof(CalendarEditingControl);
}
}

public override Type ValueType
{
get
{

return typeof(DateTime);
}
}

public override object DefaultNewRowValue
{
get
{

return DateTime.Now;
}
}
}
class CalendarEditingControl : DateTimePicker, IDataGridViewEditingControl
{
DataGridView dataGridView;
private bool valueChanged = false;
int rowIndex;

public CalendarEditingControl()
{

}

public object EditingControlFormattedValue
{
get
{
return this.Value.ToLongDateString();
}
set
{
String newValue = value as String;
if (newValue != null)
{
this.Value = DateTime.Parse(newValue);
}
}
}


public object GetEditingControlFormattedValue(
DataGridViewDataErrorContexts context)
{
return EditingControlFormattedValue;
}

public void ApplyCellStyleToEditingControl(
DataGridViewCellStyle dataGridViewCellStyle)
{
this.Font = dataGridViewCellStyle.Font;
this.CalendarForeColor = dataGridViewCellStyle.ForeColor;
this.CalendarMonthBackground = dataGridViewCellStyle.BackColor;
}

public int EditingControlRowIndex
{
get
{
return rowIndex;
}
set
{
rowIndex = value;
}
}
public bool EditingControlWantsInputKey(
Keys key, bool dataGridViewWantsInputKey)
{

switch (key & Keys.KeyCode)
{
case Keys.Left:
case Keys.Up:
case Keys.Down:
case Keys.Right:
case Keys.Home:
case Keys.End:
case Keys.PageDown:
case Keys.PageUp:
return true;
default:
return false;
}
}


public void PrepareEditingControlForEdit(bool selectAll)
{

}

public bool RepositionEditingControlOnValueChange
{
get
{
return false;
}
}

public DataGridView EditingControlDataGridView
{
get
{
return dataGridView;
}
set
{
dataGridView = value;
}
}

public bool EditingControlValueChanged
{
get
{
return valueChanged;
}
set
{
valueChanged = value;
}
}

public Cursor EditingPanelCursor
{
get
{
return base.Cursor;
}
}

protected override void OnValueChanged(EventArgs eventargs)
{
valueChanged = true;
this.EditingControlDataGridView.NotifyCurrentCellDirty(true);
base.OnValueChanged(eventargs);
}
}


}
楼主看看这个是怎么实现的.
go_now 2007-04-22
  • 打赏
  • 举报
回复
可以SelectedIndexChanged事件里面 为图片设置ToolTip属性,或者事先已经把该属性放于其他位置,触发事件时,让其显示
hiwjh20021758 2007-04-22
  • 打赏
  • 举报
回复
把ToolTip加到在活动的行上
yumanqing 2007-04-22
  • 打赏
  • 举报
回复
其实完全可以变通一下,用一个控件visable设为false,当点那个cell的时候,动态的显示相应的内容即可。
icwin 2007-04-22
  • 打赏
  • 举报
回复
mark
frankla 2007-04-20
  • 打赏
  • 举报
回复
感觉是在CELL SELECTED 后 动态显示一个空件

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧