Scroll through dataset records and display

  • Thread starter Thread starter Dvae c
  • Start date Start date
D

Dvae c

I have a form that has details of a product record that is reached by
tapping on a record in a data grid (get more details). I want the
ability for the user to also be able to scroll through the details
record (mostly text boxes). I am assumming I can use the hscrollbar
control, but not sure how to tie to dataset or data table. Does
anyone have any examples of using the hscroll control to step through
a set of records and display?

Thanks
 
what you want is called "databinding". Looking in the VS help file, I
found this topic that includes some handy sample code:


PSS ID Number: Q313635
HOW TO: Bind an Array of Objects to a Windows Form by Using Visual C# .NET



Here's some quick code that binds to a trackbar:


using System;
using System.Drawing;
using System.Windows.Forms;

public class Test : System.Windows.Forms.Form
{
CheckBox checkbox;
TrackBar trackbar;
Info[] info;

protected override void OnLoad(EventArgs e)
{
this.Text = "myform";

info = new Info[10];
for(int n = 0; n < info.Length; n++)
{
info[n] = new Info();
info[n].OnOff = n % 3 == 0;
info[n].Name = "thing:" + n;
}

checkbox = new CheckBox();
checkbox.Parent = this;
checkbox.DataBindings.Add("Checked", info, "OnOff");
checkbox.DataBindings.Add("Text", info, "Name");
checkbox.Bounds = new Rectangle(10, 10, 200, 30);

trackbar = new TrackBar();
trackbar.Parent = this;
trackbar.ValueChanged += new EventHandler(this._ValueChanged);
trackbar.Bounds = new Rectangle(10, checkbox.Bottom, 200, 40);
trackbar.Minimum = 0;
trackbar.Maximum = info.Length - 1;
trackbar.TickFrequency = 1;
}

private void _ValueChanged(object o, EventArgs e)
{
this.BindingContext[info].Position = trackbar.Value;
}

public static void Main()
{
Application.Run(new Test());
}
}


public class Info
{
bool onoff;
string name;

public bool OnOff
{
get { return this.onoff; }
set { this.onoff = value; }
}


public string Name
{
get { return this.name; }
set { this.name = value; }
}
}


NETCF Beta FAQ's -- http://www.gotdotnet.com/team/netcf/FAQ.aspx
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top