1.private void label1_Click(object sender, System.EventArgs e) //lable 空间单击事件
{
if(this.panel2.Visible==true)
{
this.panel2.Visible=false; //如果面版2是可见的则改为不可见
}
else if(this.panel1.Visible==true)
{
this.panel1.Visible=false; //和上面一样的解释
}
else if(this.panel3.Visible==true)
{
this.panel3.Visible=false;
}
this.panel4.Visible=true;
}2.private void button2_Click(object sender, System.EventArgs e) //按钮单击事件
{
try
{
adapter1.Update(ds1,tableName1); 把数据保存在数据库中,之前应该创建了adapter1对象
MessageBox.Show("保存成功!","恭喜");
}
catch(Exception err) //Exception异常类
{
MessageBox.Show(err.Message,"保存信息出 //若出现异常则提示出异常信息错!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
}
{
if(this.panel2.Visible==true)
{
this.panel2.Visible=false; //如果面版2是可见的则改为不可见
}
else if(this.panel1.Visible==true)
{
this.panel1.Visible=false; //和上面一样的解释
}
else if(this.panel3.Visible==true)
{
this.panel3.Visible=false;
}
this.panel4.Visible=true;
}2.private void button2_Click(object sender, System.EventArgs e) //按钮单击事件
{
try
{
adapter1.Update(ds1,tableName1); 把数据保存在数据库中,之前应该创建了adapter1对象
MessageBox.Show("保存成功!","恭喜");
}
catch(Exception err) //Exception异常类
{
MessageBox.Show(err.Message,"保存信息出 //若出现异常则提示出异常信息错!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
}
private void button3_Click(object sender, System.EventArgs e)
{
int num=table1.Rows.Count-1; //获取表table1的行数-1
if(num>=0) //若行数>=1 则做下面操作
{
ArrayList ar=new ArrayList(); //定义一个ArrayList对象
for(int i=num;i>=0;i--)
{
if(this.dataGrid1.IsSelected(i)) //若第i条记录是被选中的
{
ar.Add(i); //则把该记录的索引追加到ArrayList对象 ar }
}
if(ar.Count>0) //判断AR 中元素的个数
{
if(MessageBox.Show("确实要删除选中的"+ar.Count.ToString()
+"行吗? 注意:删除后就无法恢复!",
"警告",
MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.Yes)
{ //上面是删除提示对话框 若选是 则执行下面操作
for(int i=0;i<ar.Count;i++)
{
table1.Rows[int.Parse(ar[i].ToString())].Delete(); //在表中把选中的记录删除
}
}
}
else
{
MessageBox.Show("请先用鼠标单击左边灰色部分选择要删除的行(可以按住Ctrl"+"键或者Shift键同时用鼠标选中多行),然后再删除。","提示");
}
}//否则提示你因该选中要删除的记录 才能进行删除
}