如何删除键盘上的dataGridView行删除键按? c#
如何删除键盘上的选定行删除键按下(从dataGridView中删除并从数据库中删除)?如何删除键盘上的dataGridView行删除键按? c#
这里我怎么填充的dataGridView:
private void GetDate()
{
SqlDataAdapter adapter = new SqlDataAdapter("SELECT id as [ID],description as [Description],unit as [Unit], qty as [Quantity],unitRate as [Unit Rate], amount as [Amount], _datetime as [Date] FROM tbl_BOQ WHERE projectId = "+id, conn);
adapter.SelectCommand.CommandType = CommandType.Text;
DataTable table = new DataTable();
table.Clear();
adapter.Fill(table);
dataGridView1.DataSource = table;
}
您是否尝试过使用KeyPress事件DataGridView的?
然后,您可以使用DataGridView的SelectedRows属性。
我认为'CurrentRow'将是适当的 – V4Vendetta
这将取决于您的MultiSelect设置。 http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.multiselect.aspx – Paul
它的不同集合在一起 – V4Vendetta
我使用的DataGridView的KeyDown事件,并在处理程序确定它是否被按下Delete键:
if e.KeyCode == Keys.Delete...
然后找项目/行而如果获取SelectedRows属性删除,你的DataGridView的是FullRowSelect或RowHeaderSelect模式,否则,你可以确定的是这样的行:
i = SelectedCells[0].RowIndex
则:
DataGridView.Rows[i].DataBoundItem
你会那么只需从数据库中删除相应的记录,并可能刷新DataGridView的depening其在如何绑...
keydown事件不会为我开火 – minakshi
我用KeyUp因为KeyDown没有开火。 –
嗨,表现出一定的代码,如何是你的网格人口稠密?你的页面/表单看起来如何? ASP.NET或Windows窗体? –
它是Windows窗体应用程序不是ASP.NET – Amer
hei ..how你做了这个..plz帮助我 – minakshi