M
Michael Russell
Hi, I'm looking for a simple way to scroll through records, and a
BindingNavigator seemed to be it. However, I can't seem to get it to
work. I can see in an output window that I'm retrieving the correct
records, and the BindingNavigator indicates that I have 2 records.
However, using the Next and Previous buttons in the Nav don't update the
controls on the form, they always (only) show the data in the fields of
the first record.
Using the following code:
public partial class Form1 : Form
{
BindingSource bs = new BindingSource();
public Form1() {
InitializeComponent();
}
private void Form1_Load( object sender, EventArgs e ) {
FarmDataSet fds = new FarmDataSet();
DataSet ds = fds.GetDataSet();
bs.DataMember = "farm";
bs.DataSource = ds;
navFarms.BindingSource = bs;
foreach ( DataTable tbl in ds.Tables ) {
foreach ( DataRow row in tbl.Rows ) {
Console.WriteLine( "{0} ({1}) row: {2}, {3}, {4}",
tbl.TableName, tbl.Rows.Count,
row.ItemArray[ 0 ],
row.ItemArray[ 1 ],
row.ItemArray[ 2 ] );
}
}
txtName.DataBindings.Add(
new Binding( "Text", ds, "farm.name", true ) );
lblFarm.DataBindings.Add(
new Binding( "Text", ds, "farm.name", true ) );
}
}
Any help is appreciated, Thanks, Michael
BindingNavigator seemed to be it. However, I can't seem to get it to
work. I can see in an output window that I'm retrieving the correct
records, and the BindingNavigator indicates that I have 2 records.
However, using the Next and Previous buttons in the Nav don't update the
controls on the form, they always (only) show the data in the fields of
the first record.
Using the following code:
public partial class Form1 : Form
{
BindingSource bs = new BindingSource();
public Form1() {
InitializeComponent();
}
private void Form1_Load( object sender, EventArgs e ) {
FarmDataSet fds = new FarmDataSet();
DataSet ds = fds.GetDataSet();
bs.DataMember = "farm";
bs.DataSource = ds;
navFarms.BindingSource = bs;
foreach ( DataTable tbl in ds.Tables ) {
foreach ( DataRow row in tbl.Rows ) {
Console.WriteLine( "{0} ({1}) row: {2}, {3}, {4}",
tbl.TableName, tbl.Rows.Count,
row.ItemArray[ 0 ],
row.ItemArray[ 1 ],
row.ItemArray[ 2 ] );
}
}
txtName.DataBindings.Add(
new Binding( "Text", ds, "farm.name", true ) );
lblFarm.DataBindings.Add(
new Binding( "Text", ds, "farm.name", true ) );
}
}
Any help is appreciated, Thanks, Michael