从另一个实例删除DataGridView行 [英] DataGridView row deleting from another instance
本文介绍了从另一个实例删除DataGridView行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,我有以下代码创建一个datagridview控件并将其放入tabcontroll的选项卡页,我的问题是我需要某种方式(最可能是使用事件处理程序(因为我一直需要获取实时信息)选定的行)),此数据网格视图中选定行中的值将在另一个按钮中使用.有人知道我该怎么做吗?
Hello,i have the following code that creates a datagridview control and put it into a tab page of a tabcontroll, my problem is that i need to get somehow (mostlikely with an event handler (because i need allways to get the realtime selected row)) a value from a selected row in this data grid view to be used in another button. Anyone know how can i do this?
private void button1_Click(object sender, EventArgs e)
{
tabControl1.TabPages.RemoveByKey("Database ImageTable");
DataGridView datagrid1 = new DataGridView();
Utile.Customtabpage.tabpage(tabControl1, datagrid1, "Database ImageTable");
datagrid1.DataSource = Utile.DB.fillImgT(ConnectionSTR);
datagrid1.BackgroundColor = Color.White;
datagrid1.AllowUserToAddRows = false;
}
///我知道我的英语有点不好,所以我为此感到抱歉.
关于Aryx.
//I know that my english is kinda bad so i`m sorry for that.
With respect, Aryx.
推荐答案
你好
试试这个:
Hello
Try this:
private void button1_Click(object sender, EventArgs e)
{
tabControl1.TabPages.RemoveByKey("Database ImageTable");
DataGridView datagrid1 = new DataGridView();
datagrid1.SelectionChanged += new EventHandler(datagrid1_SelectionChanged);
Utile.Customtabpage.tabpage(tabControl1, datagrid1, "Database ImageTable");
datagrid1.DataSource = Utile.DB.fillImgT(ConnectionSTR);
datagrid1.BackgroundColor = Color.White;
datagrid1.AllowUserToAddRows = false;
}
然后定义一个方法:
Then Define a Method:
void datagrid1_SelectionChanged(object sender, EventArgs e)
{
var rows = ((DataGridView)sender).SelectedRows;
if (rows.Count > 0)
{
//...
}
}
这篇关于从另一个实例删除DataGridView行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文