private DataTable _table;
private SqlConnection strConnection = null;
private void Form1_Load(object sender, System.EventArgs e)
{
string selectOrder="select * from table2";
strConnection.Open();
SqlDataAdapter da = new SqlDataAdapter(selectOrder,strConnection);
_table= new DataTable();
da.Fill( _table );
GoToRecord(0);
}
private void _btnNext_Click(object sender, System.EventArgs e)
{
if( textBox1.Tag == null )
GoToRecord(0);
else
GoToRecord( ((int)textBox1.Tag) + 1 );
}
private void _btnBack_Click(object sender, System.EventArgs e)
{
if( textBox1.Tag != null )
GoToRecord( ((int)textBox1.Tag) - 1 );
}
private void GoToRecord( int index )
{
if( index > _table.Rows.Count || index < 0 )
return;
textBox1.Text = _table.Rows[ index ]["city"].ToString();
textBox1.Tag = index;
int CityID = int.Parse( _table.Rows[ index ]["Id_city"].ToString() );
string Order = "select * from table1 Where Id_city = " + CityID;
SqlDataAdapter dacbx = new SqlDataAdapter( Order, strConnection );
DataTable dt = new DataTable();
dacbx.Fill(dt);
listBox1.DataSource = dt;
listBox1.ValueMember = "ID_city";
listBox1.DisplayMember = "city";
}