datagridview 数据处理方法 修改 删除 添加 下拉类表 弹出窗口
InitializeComponent();
}
private void frmMain_Load(object sender, EventArgs e)
{
this.dataGridView1.AutoSizeColumnsMode =
System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; //表格自适应宽度
//DataCon datacon = new DataCon();
DataOperate dataoperate = new DataOperate();
string strSql = "select * from user_tb1 ";
DataSet ds = dataoperate.getDs(strSql, "user_tb1");
dataGridView1.DataSource = ds.Tables[0];
dataGridView1.Columns[0].ReadOnly = true; //列不可编写
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; //选择全行 //dataGridView1.ReadOnly = true; //只读
dataGridView1.DefaultCellStyle.SelectionBackColor = Color.YellowGreen; //选择的行为颜色
//最后一行的星号行不显示,不允许用户添加数据
dataGridView1.AllowUserToAddRows = false;
button6.Enabled = false;
button7.Enabled = false;
//初始化索引数组
for (int i = 0; i < 20; i++) intindex[i] = 255;
//*************************
//加载下拉列表框
BindSex(); // 绑定性别下拉列表框
cmb_Temp.Visible = false; // 设置下拉列表框不可见
// 添加下拉列表框事件
cmb_Temp.SelectedIndexChanged += new
EventHandler(cmb_Temp_SelectedIndexChanged);
// 将下拉列表框加入到DataGridView控件中
this.dataGridView1.Controls.Add(cmb_Temp);