要确定你查询的datagrid中有键值(不重复也可) delete from tablename where id1=datagrid(0,0) 就是要删除数据库中id1字段等于 datagrid(0,0)的那条记录如果用dataset.acceptchange()和dataadapter.update()好象有点问题哟
this.dataGrid1.CurrentCell.RowNumber this.dataGrid1.CurrentCell.ColumnNumber你是不是想找这个?下面是sdk的例子:DataGrid.CurrentCell 属性 [C#]请参见 DataGrid 类 | DataGrid 成员 | System.Windows.Forms 命名空间 | DataGridCell | FirstVisibleColumn | DataGrid 成员(Visual J# 语法) | C++ 托管扩展编程 要求 平台: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 系列, .NET Framework 精简版 - Windows CE .NET 语言 C#C++JScriptVisual Basic全部显示 获取或设置具有焦点的单元格。设计时不可用。[Visual Basic] Public Property CurrentCell As DataGridCell[C#] public DataGridCell CurrentCell {get; set;}[C++] public: __property DataGridCell get_CurrentCell(); public: __property void set_CurrentCell(DataGridCell);[JScript] public function get CurrentCell() : DataGridCell; public function set CurrentCell(DataGridCell);属性值 具有焦点的 DataGridCell。备注 设置 CurrentCell 属性将导致网格滚动,并显示该单元格是否已经可见。示例 [Visual Basic, C#] 下面的示例展示如何设置和获取当前单元格。[Visual Basic] Private Sub SetCellWithFocus(ByVal myGrid As DataGrid) ' Set the current cell to cell 1, row 1. myGrid.CurrentCell = New DataGridCell(1,1) End Sub
Private Sub DataGrid1_GotFocus(ByVal Sender As Object, ByVal e As EventArgs) Console.WriteLine(DataGrid1.CurrentCell.ColumnNumber & " " & _ DataGrid1.CurrentCell.RowNumber) End Sub[C#] private void SetCellWithFocus(DataGrid myGrid) { // Set the current cell to cell1, row 1. myGrid.CurrentCell = new DataGridCell(1,1); }
private void dataGrid1_GotFocus(object sender, EventArgs e) { Console.WriteLine(dataGrid1.CurrentCell.ColumnNumber + " " + dataGrid1.CurrentCell.RowNumber); }[C++, JScript] 没有可用于 C++ 或 JScript 的示例。若要查看 Visual Basic 或 C# 示例,请单击页左上角的“语言筛选器”按钮 。要求 平台: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 系列, .NET Framework 精简版 - Windows CE .NET
或者是这个?DataGrid.Select 方法 [C#]请参见 DataGrid 类 | DataGrid 成员 | System.Windows.Forms 命名空间 | C++ 托管扩展编程 语言 C#C++JScriptVisual Basic全部显示 选择指定行。重载列表 选择指定行。受 .NET Framework 精简版的支持。[Visual Basic] Overloads Public Sub Select(Integer) [C#] public void Select(int); [C++] public: void Select(int); [JScript] public function Select(int); 从 Control 继承。[Visual Basic] Overloads Public Sub Select() [C#] public void Select(); [C++] public: void Select(); [JScript] public function Select(); 从 Control 继承。[Visual Basic] Overloads Protected Overridable Sub Select(Boolean, Boolean) [C#] protected virtual void Select(bool, bool); [C++] protected: virtual void Select(bool, bool); [JScript] protected function Select(Boolean, Boolean); 示例 [Visual Basic, C#, C++] 注意 此示例显示如何使用 Select 的一个重载版本。有关其他可用示例,请参阅单独的重载主题。 [Visual Basic] ' Select the first row. Private Sub button7_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button7.Click myDataGrid.Select(0) End Sub 'button7_Click' Check if the first row is selected. Private Sub button8_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button8.Click If myDataGrid.IsSelected(0) Then MessageBox.Show("Row selected", "Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Else MessageBox.Show("Row not selected", "Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) End If End Sub 'button8_Click' Deselect the first row. Private Sub button11_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button11.Click myDataGrid.UnSelect(0) End Sub 'button11_Click[C#] // Select the first row. private void button7_Click(object sender, EventArgs e) { myDataGrid.Select(0); } // Check if the first row is selected. private void button8_Click(object sender, EventArgs e) { if(myDataGrid.IsSelected(0)) { MessageBox.Show("Row selected", "Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { MessageBox.Show("Row not selected", "Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } // Deselect the first row. private void button11_Click(object sender, EventArgs e) { myDataGrid.UnSelect(0); }
查一查MSDN,上面有现成的详细的例子。
delete from tablename where id1=datagrid(0,0)
就是要删除数据库中id1字段等于 datagrid(0,0)的那条记录如果用dataset.acceptchange()和dataadapter.update()好象有点问题哟
this.dataGrid1.CurrentCell.ColumnNumber你是不是想找这个?下面是sdk的例子:DataGrid.CurrentCell 属性 [C#]请参见
DataGrid 类 | DataGrid 成员 | System.Windows.Forms 命名空间 | DataGridCell | FirstVisibleColumn | DataGrid 成员(Visual J# 语法) | C++ 托管扩展编程
要求
平台: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 系列, .NET Framework 精简版 - Windows CE .NET
语言
C#C++JScriptVisual Basic全部显示
获取或设置具有焦点的单元格。设计时不可用。[Visual Basic]
Public Property CurrentCell As DataGridCell[C#]
public DataGridCell CurrentCell {get; set;}[C++]
public: __property DataGridCell get_CurrentCell();
public: __property void set_CurrentCell(DataGridCell);[JScript]
public function get CurrentCell() : DataGridCell;
public function set CurrentCell(DataGridCell);属性值
具有焦点的 DataGridCell。备注
设置 CurrentCell 属性将导致网格滚动,并显示该单元格是否已经可见。示例
[Visual Basic, C#] 下面的示例展示如何设置和获取当前单元格。[Visual Basic]
Private Sub SetCellWithFocus(ByVal myGrid As DataGrid)
' Set the current cell to cell 1, row 1.
myGrid.CurrentCell = New DataGridCell(1,1)
End Sub
Private Sub DataGrid1_GotFocus(ByVal Sender As Object, ByVal e As EventArgs)
Console.WriteLine(DataGrid1.CurrentCell.ColumnNumber & " " & _
DataGrid1.CurrentCell.RowNumber)
End Sub[C#]
private void SetCellWithFocus(DataGrid myGrid)
{
// Set the current cell to cell1, row 1.
myGrid.CurrentCell = new DataGridCell(1,1);
}
private void dataGrid1_GotFocus(object sender, EventArgs e)
{
Console.WriteLine(dataGrid1.CurrentCell.ColumnNumber +
" " + dataGrid1.CurrentCell.RowNumber);
}[C++, JScript] 没有可用于 C++ 或 JScript 的示例。若要查看 Visual Basic 或 C# 示例,请单击页左上角的“语言筛选器”按钮 。要求
平台: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 系列, .NET Framework 精简版 - Windows CE .NET
DataGrid 类 | DataGrid 成员 | System.Windows.Forms 命名空间 | C++ 托管扩展编程
语言
C#C++JScriptVisual Basic全部显示
选择指定行。重载列表
选择指定行。受 .NET Framework 精简版的支持。[Visual Basic] Overloads Public Sub Select(Integer)
[C#] public void Select(int);
[C++] public: void Select(int);
[JScript] public function Select(int);
从 Control 继承。[Visual Basic] Overloads Public Sub Select()
[C#] public void Select();
[C++] public: void Select();
[JScript] public function Select();
从 Control 继承。[Visual Basic] Overloads Protected Overridable Sub Select(Boolean, Boolean)
[C#] protected virtual void Select(bool, bool);
[C++] protected: virtual void Select(bool, bool);
[JScript] protected function Select(Boolean, Boolean);
示例
[Visual Basic, C#, C++] 注意 此示例显示如何使用 Select 的一个重载版本。有关其他可用示例,请参阅单独的重载主题。
[Visual Basic]
' Select the first row.
Private Sub button7_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button7.Click
myDataGrid.Select(0)
End Sub 'button7_Click' Check if the first row is selected.
Private Sub button8_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button8.Click
If myDataGrid.IsSelected(0) Then
MessageBox.Show("Row selected", "Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Else
MessageBox.Show("Row not selected", "Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End Sub 'button8_Click' Deselect the first row.
Private Sub button11_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button11.Click
myDataGrid.UnSelect(0)
End Sub 'button11_Click[C#]
// Select the first row.
private void button7_Click(object sender, EventArgs e)
{
myDataGrid.Select(0);
}
// Check if the first row is selected.
private void button8_Click(object sender, EventArgs e)
{
if(myDataGrid.IsSelected(0))
{
MessageBox.Show("Row selected",
"Message", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
else
{
MessageBox.Show("Row not selected",
"Message", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
}
// Deselect the first row.
private void button11_Click(object sender, EventArgs e)
{
myDataGrid.UnSelect(0);
}