像别的大虾说的,把dataGrid1的readonly属性设置为true,然后放一个“删除”按钮
“删除”按钮里面的代码:
CurrencyManager cm = (CurrencyManager)this.BindingContext[this.dataset11,"login"];
System.Data.DataView dv = (System.Data.DataView)cm.List;
ArrayList al = new ArrayList();
ArrayList us_id = new ArrayList();
for(int i = 0; i < dv.Count; i++)
{
if(this.dataGrid1.IsSelected(i))
{
us_id.Add(dv[i]["user_name"].ToString());
}
}
foreach(string i in us_id)
{
//MessageBox.Show(i.ToString(),m_int);
DataTable dt = new DataTable();
dt = this.dataset11.Tables["login"];
DataRow foundRow;
// Create an array for the key values to find.
object[]findTheseVals = new object[1];
// Set the values of the keys to find.
findTheseVals[0] = i;
foundRow = dt.Rows.Find(findTheseVals);
// Display column 1 of the found row.
if(foundRow != null)
{
foundRow.Delete();
}
}
确认以后,再dataadapter.update了,应该差不多了。