Detected Changes in Combo Box & Text Box
Hi ALL I'm having trouble figuring out..
I have one BTNCANCEL here and cmb1,cmb2,cm3, tb1,tb2.
How do i program so that it detect changes in cmb1,cmb2,cm3, tb1,tb2 and then when i click BTN cancel it will PROMPT to save yes/no [which i have already programed] if there is a change in either one of this[cmb1,cmb2,cm3, tb1,tb2] in runtime. and the program will close if there is no changes.
with reference to stored value in text file data.
[when I debug, the value stored in text file is displayed in cmb1,cmb2,cmb3,tb1,tb2]
So i would like to know how to do a program to BTNCANCEL_Click
that when it detected changes:
if (detect change)
{
using (SaveSetting settings = new SaveSetting())
{
//read properties from dialogue
//when dialogue is yes it will run save and exit application
if (settings.ShowDialog() == DialogResult.Yes)
{
save();
Application.Exit();
}
}
}
else
{
Close();
}
}
facadie
Junior Poster in Training
57 posts since Sep 2009
Reputation Points: 1
Solved Threads: 0
There's events detect that
TextBox | TextChanged
ComboBox | SelectedIndexChanged
Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
Push initial values to an array,
....
arr[0]=cmb1.Text;
....
Detect changes,
if(ar[0]!=cmd1.Text ......) {
// statements
}
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
Hi ALL I'm having trouble figuring out..
I have one BTNCANCEL here and cmb1,cmb2,cm3, tb1,tb2.
How do i program so that it detect changes in cmb1,cmb2,cm3, tb1,tb2 and then when i click BTN cancel it will PROMPT to save yes/no [which i have already programed] if there is a change in either one of this[cmb1,cmb2,cm3, tb1,tb2] in runtime. and the program will close if there is no changes.
with reference to stored value in text file data.
[when I debug, the value stored in text file is displayed in cmb1,cmb2,cmb3,tb1,tb2]
So i would like to know how to do a program to BTNCANCEL_Click
that when it detected changes:
if (detect change)
{
using (SaveSetting settings = new SaveSetting())
{
//read properties from dialogue
//when dialogue is yes it will run save and exit application
if (settings.ShowDialog() == DialogResult.Yes)
{
save();
Application.Exit();
}
}
}
else
{
Close();
}
}
i found an easier way but does anyone know how to detect combo box selected item change??
//if any of the textbox is modified
if ((TBCurrentP.Modified == true) || (TBImageL.Modified == true) || (TBDatabaseL.Modified == true))
{
if (TBNewP.Text != TBConfirmP.Text)
{
MessageBox.Show("The two passwords that you entered do not match.");
}
else
{
//calling method save
save();
this.Close();
}
}
else
Close();
}
}
[/QUOTE]
facadie
Junior Poster in Training
57 posts since Sep 2009
Reputation Points: 1
Solved Threads: 0
LOL! did you read my reply??!!
There's events detect that
TextBox | TextChanged
ComboBox | SelectedIndexChanged
Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
LOL! did you read my reply??!!
haas i did. but i dun get it? actually my programming sucks pretty much if not for school work=p sorry for that=X
facadie
Junior Poster in Training
57 posts since Sep 2009
Reputation Points: 1
Solved Threads: 0
On the ComboBox double click, VS created a handler for index changed event copy and paste your code, and solve any error if exists..
Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
LOL! did you read my reply??!!
OO but the function i want on it actually happen only when i click BTNOK?
as in when i click BTNOK, it detect changes and save else close no saving etc.
now what i have done is i detected that the text box is changed and it will save. but i duno how to go about doing that for just combo box.
cos if i use the event handler i duno how do i go about linking it with the btn?
facadie
Junior Poster in Training
57 posts since Sep 2009
Reputation Points: 1
Solved Threads: 0
This is what the event wiring for combobox selection change should look like in case you don't use VS designer:
// in form intialization:
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
// then, just create this method for your form:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
// to retrieve it's index:
int index = comboBox1.SelectedIndex;
/// if your item is text, otherwise cast to proper type:
string text = (string)comboBox1.SelectedItem;
}
hello=) i think it run withins the form?
but how do i make it so like:
when i click BTNOK it will run the program which will a check if any textbox or any combo boxes[selecteditem] have change as compare to the data store. then it will run save program.
so it's like doing a check when BTN OK is click.
facadie
Junior Poster in Training
57 posts since Sep 2009
Reputation Points: 1
Solved Threads: 0
That depends on how you are binding the controls. If you used a typed DataSet it retains the original value for the field so you could compare those. What are you binding with?
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
That depends on how you are binding the controls. If you used a typed DataSet it retains the original value for the field so you could compare those. What are you binding with?
I'm just comparing with the value of the selected item in combo boxes which is stored in text file??
facadie
Junior Poster in Training
57 posts since Sep 2009
Reputation Points: 1
Solved Threads: 0
Are you using an OleDb datasource with the text schreiber driver, or are you parsing it manually and populating the values with code?
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
Are you using an OleDb datasource with the text schreiber driver, or are you parsing it manually and populating the values with code?
Hi sorry for late reply. I suppose oledb datasource? data store in microsoft access.
facadie
Junior Poster in Training
57 posts since Sep 2009
Reputation Points: 1
Solved Threads: 0
I wrote this for your button cancel, but you can apply this logic anywhere in your program:
private void btnCancel_Click(object sender, EventArgs e)
{
bool bEditChange = false;
if ("whatever was read from text file" != (string)comboBox1.SelectedItem)
bEditChange = true;
if ("whatever was read from text file" != textBox1.Text)
bEditChange = true;
// etc.,etc.,etc.
if (bEditChange)
{
if (DialogResult.Yes == MessageBox.Show("Save Changes?", "Cancel", MessageBoxButtons.YesNo))
{
// do your file save stuff
}
}
}
Oo but how do i get the data to compare because i actually use stream writer to save the item selected into the textfile=/ ???
facadie
Junior Poster in Training
57 posts since Sep 2009
Reputation Points: 1
Solved Threads: 0
I don't understand what you haven't understood in the solution.
Handle the events generated by Combo Box and Text Box, when they are changed. Flag some value. When Button is clicked, check the flag and perform action.
How about that~ cause I'm not familiar with programming.Duh~ and i nv deal with combo box which is why until i still don't understand.................
facadie
Junior Poster in Training
57 posts since Sep 2009
Reputation Points: 1
Solved Threads: 0