我将窗体上的几个textbox控件绑定到了一个dataset上的一个datatable上。下边放一个datagrid也绑定到了这个数据源上,按条件显示其中一部分内容,点击datagrid的行时窗体上的textbox联动,用的是CurrencyManager滚动position的方式,运行是好的。但是在datatable中添加了一行后,可以得到填加行在datatable中的索引号,比如是5,但我把CurrencyManager滚动到第5行时窗体上的textbox控件显示的是第6行的内容,而滚动到最后一行时窗体上的textbox显示的才是我插入的内容,也就是说插入的行在datatable中号的索引是5,而插入的行在CurrencyManager的position属性是最后一行
请教,该如何插入的行在CurrencyManager的position属性也一样是5
请教,该如何插入的行在CurrencyManager的position属性也一样是5
解决方案 »
- 正则批量替换
- HttpWebRequest 多线程 同步 异步 的问题
- C#winform crystal report加載問題
- 怎样用progressbar这个控件来显示dataGriView读取和保存数据进度?
- c#创建文件
- SQL SERVER2000t .NET2005
- 关于marshal的用法!!(急)
- 天啊,<ItemTemplate>是正确的,但<EditItemTemplate>却错了,救命啊.
- 各位帮帮忙!
- c#事件中e怎么用?
- 菜鸟的问题(各位大虾帮忙啊):从richEiditBox中把输入的一串数字(含空格和回车)读入到一个二维数组中时,怎么判断回车?怎么把读到的
- 更新DataSet时,删除语句定义不起作用?
SqlConnection conn = new SqlConnection("user id=sa;data source=localhost;persist security info=true;initial catalog=Northwind;password=sa");
DataSet ds = new DataSet();
string sql = "select top 10 CustomerID, CompanyName from Customers";
SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);
adapter.Fill(ds);this.dataGrid1.SetDataBinding(ds, ds.Tables[0].TableName);
this.BindControl(ds.Tables[0]);
private CurrencyManager myCurrencyManager;
private void BindControl(DataTable myTable)
{
textBox1.DataBindings.Add("Text", myTable, "CompanyName");
myCurrencyManager = (CurrencyManager)this.BindingContext[myTable];
myCurrencyManager.Position = 0;
}//添加新行
private void button2_Click(object sender, System.EventArgs e)
{
DataSet ds = (DataSet)this.dataGrid1.DataSource;
DataTable table = ds.Tables[0];
DataRow row = table.NewRow();
row[0] = 1;
row[1] = "我的公司";
table.Rows.Add(row);}
//同步数据
private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
{
this.myCurrencyManager.Position = this.dataGrid1.CurrentCell.RowNumber;
}
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp