【问题标题】:display next prior Last record on dataset in winform在winform中显示数据集上的下一条上一条记录
【发布时间】:2014-10-15 13:28:05
【问题描述】:

我想在按钮单击 NextPriorLast 记录在 winform 上的文本框中显示数据集的记录。那么我该怎么做呢。我没有在表单上使用bindingNavigator。提前致谢。

【问题讨论】:

  • 有什么问题?将当前行索引存储在字段中,然后相应地前进/后退。

标签: .net winforms c#-4.0


【解决方案1】:

将当前的行索引存储在一个字段中,其余的很简单(ds 是你的DataSet):

private int RowIndex { get; set; }

private void Navigate(int recordIndex)
{
    if (recordIndex < 0 || recordIndex >= ds.Tables[0].Rows.Count)
        throw new ArgumentException("The record-index must be between 0 and row-count-1", "recordIndex");
    DataRow row = ds.Tables[0].Rows[recordIndex];
    string field = row.Field<string>("ColumnName");
    yourTextBox.Text = field;
}
private void btnNext_Click(object sender, EventArgs args)
{ 
    int rowIndex = RowIndex + 1;
    if(rowIndex >= ds.Tables[0].Rows.Count)
        rowIndex = 0;
    Navigate(rowIndex);
}
private void btnPrior_Click(object sender, EventArgs args)
{
    int rowIndex = RowIndex - 1;
    if (rowIndex < 0)
        rowIndex = ds.Tables[0].Rows.Count - 1; // go to last
    Navigate(rowIndex);
}
private void btnFirst_Click(object sender, EventArgs args)
{
    Navigate(0);
}
private void btnLast_Click(object sender, EventArgs args)
{
    Navigate(ds.Tables[0].Rows.Count - 1);
}

【讨论】:

    猜你喜欢
    • 2021-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-06
    • 1970-01-01
    相关资源
    最近更新 更多