I want to display records position in a "navigation textbox" once they are pulled from a table, something similar to the figure below (also provided as an attachment):
C:\navigate.JPG
What I want is for the record displayed in the text boxes to be reflected in the records navigation section. When I click the next button, the position of the records in the "navigation-textbox" should be incremented accordingly to reflect the correct change, that is, move from, say, 2 of 6 to 3 of 6. But this is not happening. In the navigation textbox, the message remains constant at "1 of 6" no matter which record is being displayed in the textboxes above.
I have looked at various examples on the Internet including here: http://msdn.microsof...v=vs.71%29.aspx but I cannot seem to understand what I am not doing right.
Plus, I have noticed that my requirement can be achieved by using the in-built Visual Studio.Net Binding Navigator functionality. I have tried it and it works perfectly. But I also realize that there are times when I may need to approach the same task differently depending upon the requirement. Therefore I decided to find out how to do a "custom-built" Binding Navigator. But now I am stuck.
I have included the relevant code below:
....
....
System.Data.SqlClient.SqlConnection con;
DataSet ds1;
System.Data.SqlClient.SqlDataAdapter da;
int MaxRows = 0;
int inc = 0;
private void Form1_Load(object sender, EventArgs e)
{
con = new System.Data.SqlClient.SqlConnection();
ds1 = new DataSet();
con.ConnectionString="Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Empl.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
string sql = "SELECT * From tblEmployees";
da = new System.Data.SqlClient.SqlDataAdapter(sql, con);
con.Open();
da.Fill(ds1, "Employees");
showDataPosition();
MaxRows = ds1.Tables["Employees"].Rows.Count;
con.Close();
MessageBox.Show("MS SQL database is now closed");
}
private void showRecordPosition()
{
DataRow dRow = ds1.Tables["Employees"].Rows[inc];
txtEmployeeID.Text = dRow.ItemArray.GetValue(0).ToString();
txtFirstName.Text = dRow.ItemArray.GetValue(1).ToString();
txtLastName.Text = dRow.ItemArray.GetValue(2).ToString();
txtJobTitle.Text = dRow.ItemArray.GetValue(3).ToString();
int eiCount, eiPosition;
eiPosition = 1;
eiCount = this.BindingContext[ds1, "Employees"].Count;
eiPosition = this.BindingContext[ds1, "Employees"].Position + 1;
if (eiCount == 0)
{
txtNavigate.Text = "(There are No Records)";
}
else
{
txtNavigate.Text = eiPosition.ToString() + " of " + eiCount.ToString();
}
}
private void btnFirst_Click(object sender, EventArgs e)
{
if (inc != 0)
{
inc = 0;
showRecordPosition();
}
else
{
MessageBox.Show("Beginning of Records");
}
}
....
....
What am I missing?
I am relatively new to programming and I am using VS 2005.
Thanking you in advance.
Joe
This post has been edited by joemb: 02 September 2011 - 02:51 AM

New Topic/Question
Reply



MultiQuote








|