请教有个DataTable

sanmuncle 2003-10-18 08:56:53
有个DataTable,第一列为主键值,如何根据一个主键值,得到该值位于表中的第几行?
...全文
33 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
sanmuncle 2003-10-18
  • 打赏
  • 举报
回复
LesleyChiu(鱼头) :这样是可以实现,数据少还可以,多了感觉有点影响速度。
Stevetan81(Steve) :CurrencyMangager需要和数据源帮定,但我不希望那样去做。
Stevetan81 2003-10-18
  • 打赏
  • 举报
回复
你可以使用CurrencyMangager类
private CurrencyManager myCurrencyManager;

private void BindControl(DataTable myTable){
// Bind a TextBox control to a DataTable column in a DataSet.
textBox1.DataBindings.Add("Text", myTable, "CompanyName");
// Specify the CurrencyManager for the DataTable.
myCurrencyManager = (CurrencyManager)this.BindingContext[myTable];
// Set the initial Position of the control.
myCurrencyManager.Position = 0;
}

private void MoveNext(CurrencyManager myCurrencyManager){
if (myCurrencyManager.Position == myCurrencyManager.Count - 1){
MessageBox.Show("You're at end of the records");
}
else{
myCurrencyManager.Position += 1;
}
}

private void MoveFirst(CurrencyManager myCurrencyManager){
myCurrencyManager.Position = 0;
}

private void MovePrevious(CurrencyManager myCurrencyManager ){
if(myCurrencyManager.Position == 0) {
MessageBox.Show("You're at the beginning of the records.");
}
else{
myCurrencyManager.Position -= 1;
}
}

private void MoveLast(CurrencyManager myCurrencyManager){
myCurrencyManager.Position = myCurrencyManager.Count - 1;
}
LesleyChiu 2003-10-18
  • 打赏
  • 举报
回复
for循环找咯。!!

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧