在form里datagridview本身里面没有listbox,用代码怎么才能把listbox加到datagridview的columns中??
解决方案 »
- 求大神给个ASP.NET C#语言写的网站设计的源码
- 请WEB高手进来帮助我解决我们企业网的一个问题?
- 如何用代码实现退到上一页?
- c#实现一个功能?
- richtextbox文字读取
- 如何通过javascript获取整个文档的内容?
- c# 我想在一个软件里添加一个在线咨询的功能
- ---------在用vb.net编写asp.net..在条件符合的情况...就可以弹出一个消息框------
- .Net Framework SDK问题,谁知道?
- 如何在asp.net的DataGrid中修改数据时,使DataGrid的一列变成下拉列表框的样式?
- 如何想实现这样的数据绑定 c# DataSet
- sql 2005 中的类型 uniqueidentifier,在c#中对应哪个类型?
中判断是否该显示Listbox
是:
if (dataGridView1.CurrentCell.ColumnIndex==0)
{ Rectangle rect = dataGridView1.GetCellDisplayRectangle(dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentCell.RowIndex, false);
Listbox.Left = rect.Left;
Listbox.Top = rect.Top;
Listbox.Width = rect.Width;
Listbox.Height = rect.Height;
Listbox.Visible = true;
}
{ Rectangle rect = dataGridView1.GetCellDisplayRectangle
这是什么意思了...一运行就报这个错误
是一句话!
较麻烦. listbox的没做过, 有一个用DateTimePicker的.
public class CalendarColumn : DataGridViewColumn
{
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;
}
}
} public class CalendarCell : DataGridViewTextBoxCell
{ public CalendarCell()
: base()
{ // this.Style.Format = "d ";
} public override void InitializeEditingControl(int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
{ base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle);
CalendarEditingControl ctl = DataGridView.EditingControl as CalendarEditingControl;
ctl.Value = Convert.ToDateTime(this.Value.ToString());
} public override Type EditType
{
get
{
return typeof(CalendarEditingControl);
}
} public override Type ValueType
{
get
{
return typeof(DateTime);
}
} public override object DefaultNewRowValue
{
get
{
DateTime a = Convert.ToDateTime("00:00:00");
return a;
}
}
} class CalendarEditingControl : DateTimePicker, IDataGridViewEditingControl
{ DataGridView dataGridView;
private bool valueChanged = false;
int rowIndex; public CalendarEditingControl()
{
// this.Format = DateTimePickerFormat.Time;
this.Format = DateTimePickerFormat.Custom;
this.CustomFormat = "HH:mm";
this.ShowUpDown = true;
}
public object EditingControlFormattedValue
{
get
{
return this.Value.ToLongTimeString();
}
set
{
String newValue = value as String; if (newValue != null)
{ this.Value = Convert.ToDateTime(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);
}
}
刚才你写的试过了..没有效果
谢谢
cmbPointType.Visible = false;
cmbPointType.SelectedIndexChanged+=new EventHandler(cmbPointType_SelectedIndexChanged);
this.dgvGCPs.Controls.Add(cmbPointType);public void LoadcomboBoxPointType()
{
//透明色初始化设置
cmbPointType.DrawMode = DrawMode.OwnerDrawFixed;
cmbPointType.DropDownStyle = ComboBoxStyle.DropDownList;
cmbPointType.DrawItem += new DrawItemEventHandler(cmbTransparence_DrawItem);
mbPointType.ItemHeight = 18;
cmbPointType.BeginUpdate();
cmbPointType.Items.Clear();
//循环遍历添加每一项
cmbPointType.Items.Add("控制点");
cmbPointType.Items.Add("检查点");
cmbPointType.EndUpdate();
}private void dataGridView_Click(object sender, EventArgs e)
{
if (dataGridView1.CurrentCell.ColumnIndex == (int)GeoRectificationTable.TableAttributeIndex.pointType && dataGridView1.CurrentCell.RowIndex < (myGeoRectificationTable.BasePointNumber > myGeoRectificationTable.WarpPointNumber ? myGeoRectificationTable.BasePointNumber : myGeoRectificationTable.WarpPointNumber))
{
Rectangle rect = dataGridView1.GetCellDisplayRectangle(dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentCell.RowIndex, false);
string sexValue = dataGridView1.CurrentCell.Value.ToString();
cmbPointType.Left = rect.Left;
cmbPointType.Top = rect.Top;
cmbPointType.Width = rect.Width;
cmbPointType.Height = rect.Height;
cmbPointType.Visible = true;
}
else
{
cmbPointType.Visible = false;
}
}private void cmbTransparence_DrawItem(object sender, DrawItemEventArgs e)
{
ComboBox cmbTransparence = (ComboBox)(sender);
if (e.Index < 0) return; e.DrawBackground(); //得到绘制的矩形框
Rectangle rect = new Rectangle(4, e.Bounds.Top + 2, e.Bounds.Height + 10, e.Bounds.Height - 4); string colorName = cmbTransparence.Items[e.Index].ToString();
Font pFont = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular); //在指定的矩形内绘制文本
e.Graphics.DrawString(colorName, pFont, Brushes.Black, new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
//在指定的边界范围内绘制聚集框
e.DrawFocusRectangle();
}