Windows Develop Bookmark and Share   
 index > Windows Forms Sample Applications > moving to the first,previous,next,last records
 

moving to the first,previous,next,last records

i have to get the first,previous,next,last records on clicking of subsequent buttons.I m using textboxes for displaying the values of the record.But i am unable to move to the next,previous,last records as by default 1st record is displayed.Any help please

private void Form1_Load(object sender, EventArgs e)

{

binddata();


editdata();

}

//code for filling the gridview

public void binddata()

{

DataSet ds = new DataSet();

SqlDataAdapter da = new SqlDataAdapter("select * from cities", sqlcon);

da.Fill(ds,

"fill");

dataGridView1.DataSource = ds.Tables[0];

}


public

void editdata()

{

//code for editing the data to the textboxes on click of row in datagridview

Object no = dataGridView1.CurrentRow.Cells[1].Value;

SqlDataAdapter da3 = new SqlDataAdapter("select * from cities where number= " + no + "", sqlcon);

da3.TableMappings.Add(

"Table", "edit");

da3.Fill(ds3);

if (ds3.Tables["edit"].Rows.Count > 0)

{

txtno.DataBindings.Add(

"Text", ds3, "edit.number");

txtcity.DataBindings.Add(

"Text", ds3, "edit.city");

}

}

private

void btnfirst_Click(object sender, EventArgs e)

{

this.BindingContext[ds3, "edit"].Position = 0;

}

private void btnprevious_Click(object sender, EventArgs e)

{

this.BindingContext[ds3, "edit"].Position =

(

this.BindingContext[ds3, "edit"].Position - 1);

}

private void btnnext_Click(object sender, EventArgs e)

{

this.BindingContext[ds3, "edit"].Position =

(

this.BindingContext[ds3, "edit"].Position + 1);

}

private void btnlast_Click(object sender, EventArgs e)

{

this.BindingContext[ds3, "edit"].Position =

(

this.BindingContext[ds3, "edit"].Count - 1);

}

usha.talasila  Monday, July 13, 2009 3:11 PM

Hi usha.talasila,

Would you mind providing me the count and the type of the binding manager? You can follow this code snippet:
int count = this.BindingContext[ds3, "edit"].Count;

string typeName = this.BindingContext[ds3, "edit"].GetType().FullName;

I tested the similar code snippet, but it works fine. From my experience, the root cause is mostly in these cases:

1. The count of the binding manager is 1.

2. The type of the binding manager is PropertyManager. Since the PropertyManager only maps a single value to a control, so that we cannot move the position.

Let me know if this helps.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Wednesday, July 15, 2009 12:56 PM

Hi,

We are changing the issue type to “General Discussion�because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question�by opening the Options list at the top of the post window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.

Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Monday, July 20, 2009 10:00 AM

You can use google to search for other answers

Custom Search

More Threads

• Conflict resolution does nothing
• how I can get the name of last event in VB.NET?
• Altering Task Vision Source
• UserInterface - Outlook Calendar Look and Feel
• This is just for testing...
• possible changes to Computer settings
• Reintroduce Animal: Server always returns a empty list
• Is the server up???
• TaskVision Installation Problem
• using n-tier architecture for winforms