I currently have a windows form application composed of a textbox and two buttons (previous and next) The textbox is bound to the name of a Person on a list. Previous and Next button changes the position of the BindingManager by 1 (either increment or decrement).
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private List<Person> stringList;
BindingManagerBase bindingManager;
public Form1()
{
InitializeComponent();
stringList = new List<Person>();
stringList.Add(new Person{ name = "person1" });
stringList.Add(new Person { name = "person2" });
stringList.Add(new Person { name = "person3" });
stringList.Add(new Person { name = "person4" });
bindingManager = this.BindingContext[stringList];
bindingManager.CurrentChanged += handleCurrentChanged;
textBox1.DataBindings.Add(new Binding("Text", stringList, "name"));
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void handleCurrentChanged(object sender, EventArgs e)
{
MessageBox.Show("handleCurrentChanged");
}
private void button1_Click(object sender, EventArgs e)
{
bindingManager.Position++;
}
private void button2_Click(object sender, EventArgs e)
{
bindingManager.Position--;
}
}
public class Person
{
public String name { get; set; }
}
}
What is needed is to prompt the user whenever he/she presses the previous or next button whether to save his changes or not. But only if he made some changes to the textbox.
My problem is how to know whether there has been some changes to the Person object so that I can initiate the prompt. I had intended to use BindingManagerBase's currentChanged event but this only checks if you have changed which item you are working on the list. I also can't check for the textbox since the previous and next button manipulate it also, which I do not want to prompt the user for.