Reputation: 3494
i want to display record of the Dataset in text box on button click Next
, Prior
and Last
record on winform . So how can i do this . I am not using bindingNavigator
on the form . Thanks in advance.
Upvotes: 0
Views: 137
Reputation: 460238
Store the current row-index in a field, the rest is straight-forward (ds
is your 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);
}
Upvotes: 1