下面是如何設置的默認值,禁用電池:
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Column1.DataSource = new int[] { 1, 2, 3 };
Column1.DataPropertyName = "Number";
dataGridView1.DataSource = new[]
{
new { Number=1 },
new { Number=2 },
new { Number=3 },
new { Number=1 }
};
}
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == Column1.Index && e.RowIndex == (dataGridView1.Rows.Count - 1))
{
DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)dataGridView1[e.ColumnIndex, e.RowIndex];
cell.Value = 2;
cell.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
cell.ReadOnly = true;
}
}
}
}
@Josh M .:還沒有啓用屬性((DataGridViewComboBoxColumn)dg.Columns [「Status」])。En ... – VeecoTech 2011-03-21 03:44:09
我們是不是在談論同一個控件?此控件具有我提到的兩個屬性:http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxeditingcontrol.aspx – 2011-03-21 03:56:57
哦! DataGridViewComboBoxColumn!好吧,讓我檢查它... – 2011-03-21 03:57:32