问题描述
您好,我在使用datagridview时遇到了一些问题。
所以这样...
我有这个代码:
private void frmOwners_Load(object sender,System.EventArgs e )
完成后,还有2个SelectionChanged事件被激活
void void FillGrid()
{
DataTable myDt = new DataTable();
myDt = DBEngine.GetAllRecords(); //它是我自己获取数据的方法...
myDt.Columns [0] .Column.ColumnMapping = MappingType.Hidden;
myDt.Columns .Column.ColumnMapping = MappingType.Hidden;
myDt.Columns [7] .Column.ColumnMapping = MappingType.Hidden ;
myDataGrid.DataSource = myDt; //这会触发第一个selectionChanged方法...
}
void void myDataGrid_SelectionChanged(object sender,EventArgs e)
{
//这里是一些代码,但它被触发了3次
代码中的最后一行触发了selectionchanged方法,但是,它被逐个激发了3次...
有谁知道为什么???
是不是因为3列映射
THX for any help
metaller
PS:哦,我忘了...使用XP,VS2005,NET2.0
Hi there,I've some problem using datagridview..
So like this...
I've this code:
private void frmOwners_Load(object sender, System.EventArgs e)
{
this.FillGrid();
//after this is done, there are fired 2 more SelectionChanged events
}
private void FillGrid()
{
DataTable myDt = new DataTable();
myDt = DBEngine.GetAllRecords(); //its my own method for getting data...
myDt.Columns[0].Column.ColumnMapping = MappingType.Hidden;
myDt.Columns.Column.ColumnMapping = MappingType.Hidden;
myDt.Columns[7].Column.ColumnMapping = MappingType.Hidden;
myDataGrid.DataSource = myDt; //This fires the first selectionChanged method...
}
private void myDataGrid_SelectionChanged(object sender, EventArgs e)
{
//here is some code, but it's fired 3 times
}
The last row from code fires the selectionchanged method, but, it's fired 3times one by one...
Does anyone know why???
Is it because the 3 columnmappings?
THX for any help
metaller
PS: Oh, i forgot... using XPs, VS2005, NET2.0
推荐答案
我已经尝试了你的代码,它运行正常。我不知道代码中的最后一行,哪行代码。你能准确提供吗。
I've tried your code, it works fine. I don't know your last row from code, which line code. Can you provide it exactly.
谢谢。
这篇关于DataGridView SelectionChanged事件被触发3次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!