//dataGridView1
namespace MySchool
{
public partial class InStoreroomInsertFrom : Form
{
public InStoreroomInsertFrom()
{
InitializeComponent();
} DataTable dt;
//初始化时 设置好了一个自定义的 DataTable
private void InStoreroomInsertFrom_Load(object sender, EventArgs e)
{
dt = new DataTable("List");
dt.Columns.Add("SubjectCode", System.Type.GetType("System.String"));
dt.Columns.Add("materialcode", System.Type.GetType("System.String"));
dt.Columns.Add("apellation", System.Type.GetType("System.String"));
dt.Columns.Add("summary", System.Type.GetType("System.String"));
dt.Columns.Add("amount", System.Type.GetType("System.String"));
dt.Columns.Add("MRP", System.Type.GetType("System.String"));
}
//单击 button1时 添加数据 到dataGridView1
private void button1_Click(object sender, EventArgs e)
{
DataRow dr = dt.NewRow();
dr["SubjectCode"] = textBox1.Text;
dr["materialcode"] = textBox2.Text;
dr["apellation"] = textBox3.Text;
dr["amount"] = textBox5.Text;
dr["MRP"] = textBox4.Text;
dr["summary"] = textBox6.Text;
dt.Rows.Add(dr);
dataGridView1.DataSource = dt;
} // 单击 button2 时 删除我在 dataGridView1 选中的一行 数据 private void button2_Click(object sender, EventArgs e)
{ // 求助 ??????????????????? 这里我要怎么才能删除选中的一行 数据 实现
}
}
}
namespace MySchool
{
public partial class InStoreroomInsertFrom : Form
{
public InStoreroomInsertFrom()
{
InitializeComponent();
} DataTable dt;
//初始化时 设置好了一个自定义的 DataTable
private void InStoreroomInsertFrom_Load(object sender, EventArgs e)
{
dt = new DataTable("List");
dt.Columns.Add("SubjectCode", System.Type.GetType("System.String"));
dt.Columns.Add("materialcode", System.Type.GetType("System.String"));
dt.Columns.Add("apellation", System.Type.GetType("System.String"));
dt.Columns.Add("summary", System.Type.GetType("System.String"));
dt.Columns.Add("amount", System.Type.GetType("System.String"));
dt.Columns.Add("MRP", System.Type.GetType("System.String"));
}
//单击 button1时 添加数据 到dataGridView1
private void button1_Click(object sender, EventArgs e)
{
DataRow dr = dt.NewRow();
dr["SubjectCode"] = textBox1.Text;
dr["materialcode"] = textBox2.Text;
dr["apellation"] = textBox3.Text;
dr["amount"] = textBox5.Text;
dr["MRP"] = textBox4.Text;
dr["summary"] = textBox6.Text;
dt.Rows.Add(dr);
dataGridView1.DataSource = dt;
} // 单击 button2 时 删除我在 dataGridView1 选中的一行 数据 private void button2_Click(object sender, EventArgs e)
{ // 求助 ??????????????????? 这里我要怎么才能删除选中的一行 数据 实现
}
}
}
解决方案 »
- 关于字符串流
- 关于COM和64位电脑的问题
- 请问怎么让RadioButtonList控件中的选择对齐呢?好像没有这个属性吧?
- 请假下动态添加 datagird 的模板列问题
- 这样的C#语句函数正确吗?
- 在windowform里面发邮件
- 各位老大,OrdersDataTable里怎样添加父表Customers中的FirstName字段啊?
- 请问这段代码有什么问题,为什么到oracleConnection.Open();这一行跳出异常?(在线等!!!)
- 调用WebService的问题???
- string format 对齐问题
- 关于ContextMenuStrip中dropDown选项问题(winform)
- C#讀取XML節點問題
然后根据RowState过滤。
GridViewRow gvr = GridView1.SelectedRow;
int id = int.Parse(gvr.Cells[0].Text);
//SqlConnection conn = new SqlConnection("......");
//SqlCommand cmd = new SqlCommand("delete from table1 where id="+id+"",conn);
//conn.Open();
//cmd.ExecuteNonquery();
{
// 当没有点中单元格时处理异常
try
{
int identityRow = int.Parse(this.gdvFactory.CurrentRow.Cells["identity"].Value);
for (int i = 0; i < dtFactory.Rows.Count; i++)
{
if (dtFactory.Rows[i].RowState != DataRowState.Deleted)
{
int indetity = int.Parse(dtFactory.Rows[i]["identity"]);
if (identityRow == indetity)
{
dtFactory.Rows[i].Delete();
break;
}
//调用事件
}
}
}
catch { }
}