通过主键进行比较,我做软件时的代码如下(this.m_KeyCol表示主键所在的列,整型):
/// <summary>
/// 根据DataGrid的内容,返回当前DataSet中的行的索引
/// </summary>
/// <returns>成功返回索引,否则返回-1</returns>
protected int CurRowIndex
{
get
{
int result=-1;
if(this.m_Table.Rows.Count>0)
{
string keyvalue=this.dataGridInfo[dataGridInfo.CurrentRowIndex,this.m_KeyCol].ToString();
for(int i=0;i<this.m_Table.Rows.Count;i++)
{
if(this.m_Table.Rows[i][m_KeyCol].ToString()==keyvalue)
{
//找到
result=i;
break;
}
}//end for
}
return result;
}
set
{
int newPos=(int)value;
if(newPos>=0 && newPos<m_Table.Rows.Count && dataGridInfo.CurrentRowIndex!=newPos)
this.dataGridInfo.CurrentRowIndex=newPos;
}
}
/// <summary>
/// 根据DataGrid的内容,返回当前DataSet中的行的索引
/// </summary>
/// <returns>成功返回索引,否则返回-1</returns>
protected int CurRowIndex
{
get
{
int result=-1;
if(this.m_Table.Rows.Count>0)
{
string keyvalue=this.dataGridInfo[dataGridInfo.CurrentRowIndex,this.m_KeyCol].ToString();
for(int i=0;i<this.m_Table.Rows.Count;i++)
{
if(this.m_Table.Rows[i][m_KeyCol].ToString()==keyvalue)
{
//找到
result=i;
break;
}
}//end for
}
return result;
}
set
{
int newPos=(int)value;
if(newPos>=0 && newPos<m_Table.Rows.Count && dataGridInfo.CurrentRowIndex!=newPos)
this.dataGridInfo.CurrentRowIndex=newPos;
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货