日期:2014-05-19  浏览次数:21070 次

在datagridview中增加按钮的问题。
1、请问如何在datagridview中某一列的旁边再放置个按钮,   点完该按钮后弹出新窗体选值,将选完的值填充到该单元格。(不用datagridviewbuttoncolumn)
2、将datetimepicker控件放入datagridview
3、在单元格中敲回车,   自动将焦点移动到下一单元格



------解决方案--------------------
1:添加一个模板列,在模板中添加所要添加的按钮.....
2:也是在模板中添加控件了...

------解决方案--------------------
推荐用第三方控件,如Infragistics NetAdvantage 2006 .上面功能比较齐全
------解决方案--------------------
自己画一个button在那里,然后判断鼠标点击位置
------解决方案--------------------
lz:MSDN有一篇很好的文章《在 Windows 窗体 DataGridView 单元格中承载控件》,我发给你看看,相信对你有用:
using System;
using System.Windows.Forms;

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

public override DataGridViewCell CellTemplate
{
get
{
return base.CellTemplate;
}
set
{
// Ensure that the cell used for the template is a CalendarCell.
if (value != null &&
!value.GetType().IsAssignableFrom(typeof(CalendarCell)))
{
throw new InvalidCastException( "Must be a CalendarCell ");
}
base.CellTemplate = value;
}
}
}

public class CalendarCell : DataGridViewTextBoxCell
{

public CalendarCell()
: base()
{
// Use the short date format.
this.Style.Format = "d ";
}

public override void InitializeEditingControl(int rowIndex, object
initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
{
// Set the value of the editing control to the current cell value.
base.InitializeEditingControl(rowIndex, initialFormattedValue,
dataGridViewCellStyle);
CalendarEditingControl ctl =
DataGridView.EditingControl as CalendarEditingControl;
ctl.Value = (DateTime)this.Value;
}

public override Type EditType
{
get
{
// Return the type of the editing contol that CalendarCell uses.
return typeof(CalendarEditingControl);
}
}

public override Type ValueType
{
get
{
// Return the type of the value that CalendarCell contains.
return typeof(DateTime);
}
}

public override object DefaultNewRowValue
{
get
{
// Use the current date and time as the default value.
return DateTime.Now;
}
}
}

class CalendarEditingControl : DateTimePicker, IDataGridViewEditingControl
{
DataGridView dataGridView;
private bool valueChanged = false;
int rowIndex;

public CalendarEditingControl()
{
this.Format = DateTimePickerFormat.Short;
}

// Implements the IDataGridViewEditingControl.EditingControlFormattedValue
// property.
public object EditingControlFormattedValue
{
get
{
return this.Value.ToShortDateString();
}
set
{
String newValue = value as String;
if (newValue != null)