473,386 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how to test if a selected index has just been change ?

Hello
This is, below, a piece of code that I have a problem with:

In the program (french description here
http://www.scalpa.info/carre_install...aide_carre.htm) a number is
generated in the interval given by the value of nudNumMin and nudNumMax.
In the user interface can be created several "projects" appearing in a
listbox, which each have their
characteristics. By clicking on the project in the listbox, controls must
display values for this project( selected at the moment it was build).
If in a project carréA nudNumMax is 20 and nudNumMin is 15 and
in the project carréB nudNumMax is 10 and nudNumMin is 5: When I pass from
one to the other that triggers the warning message and corrects my data
while it should not because min is much lower than max within the same
Project ...

So where and How can I test the values returned by numericupdown controls
only within the same project but not when I change project clicking in the
list box?
THANKS FOR YOUR HELP
Pascal
--
the code :
private void SetMazeGroupControls()
{
_boInitilizing = true;

// misc
chbNewRow.Checked = _currParam.NewRow;
nudMazeCount.Value = (decimal)_currParam.Count;

// generation
nudMazeWidth.Value =
(decimal)_currParam.GenerationData.CarreWidth;
nudNumMin.Value = (decimal)_currParam.GenerationData.NumberMin;
nudNumMax.Value = (decimal)_currParam.GenerationData.NumberMax;
nudCellSize.Value = (decimal)_currParam.ExerciseData.CellSize;
.......

private void lbxMaze_SelectedIndexChanged( object sender, EventArgs e )
{
int iSelected = lbxMaze.SelectedIndex;

if( iSelected >= 0 )
{
MazeItemData item = lbxMaze.Items[ iSelected ] as
MazeItemData;
_currParam = item;
SetMazeGroupControls();
if( Properties.Settings.Default.MarkCurrentMaze )
ValueChanged( false );
}

HandleMazeListButtons();
}

........
private void nudNumMin_ValueChanged(object sender, EventArgs e)
{

if (nudNumMin.Value >= nudNumMax.Value)
{
MessageBox.Show("La valeur minimale doit être inférieure à
la valeur maximale.", "Valeur invalide ", MessageBoxButtons.OK);

nudNumMin.Value = nudNumMax.Value - 1;
}

_currParam.GenerationData.NumberMin = (int)nudNumMin.Value;
ValueChanged(true);
}

private void nudNumMax_ValueChanged(object sender, EventArgs e)
{
if (nudNumMax.Value <= nudNumMin.Value)
{
MessageBox.Show("La valeur maximale doit être supérieure à
la valeur minimale.", "Valeur invalide ", MessageBoxButtons.OK);

nudNumMax.Value = nudNumMin.Value + 1;
}
_currParam.GenerationData.NumberMax = (int)nudNumMax.Value;
ValueChanged(true);
}
http://www.scalpa.info

Jul 2 '08 #1
5 1396
Hello and thanks for this quick response.

I had thinking of "a flag?" able to "switch on or off" a piece of code : i
will dig that and 'll try to find a piece of code that explain how to do
that in C# that i am discovering this year.
Do you know a place to read how to set a flag ?

Thanks to inform me about usenet : if i understood after this "--" only
signature must remain ?

pascal

Just add a flag to your class that you can set while updating the
project based on the ListBox selection change. Set the flag before you
adjust the numeric controls, and clear it after you're done. Then, in the
numeric control event handlers, don't do any range checking if the flag is
set.

By the way, next time you post code, you might consider not putting it in
your signature (that is, following the specific Usenet-standard signature
delimiter "-- "). Some newsreaders will format it differently, making it
harder to read, and other newsreaders will strip it out altogether, making
it impossible to read. Obviously, that may limit your audience somewhat
(especially the latter problem :) ).

Pete
--
http://www.scalpa.info
http://scalpa98.blogspot.com/
http://scalpa-production.blogspot.com/
Jul 2 '08 #2
On Wed, 02 Jul 2008 01:02:34 -0700, Pascal <sc************@scalpa.info>
wrote:
Hello and thanks for this quick response.

I had thinking of "a flag?" able to "switch on or off" a piece of code :
i will dig that and 'll try to find a piece of code that explain how to
do that in C# that i am discovering this year.
Do you know a place to read how to set a flag ?
By "flag" I simply mean a variable of type "boolean". Sorry I was
imprecise. The word "flag" is commonly used, but I admit that it would
have been better to just use the type name.
Thanks to inform me about usenet : if i understood after this "--" only
signature must remain ?
Almost. The space after the two hyphens is important. But yes, after "--
" (note the space), only a signature should appear.

Pete
Jul 2 '08 #3
hello Pete

I did this without success.... don't know why... any idea ?
some where at the beginning of the code boolean declaration :

private bool flagCheckIcomeFromLstBx = false ;
private string _strFile = string.Empty; // loaded file name
(including full path
private bool _boChanged = false; // any changes made on
the current parameters
private bool _boInitilizing = true; // true = initialization
running, suppress redrawing
//..... then if index of listbox changes i turn "on" the flag
private void lbxMaze_SelectedIndexChanged( object sender, EventArgs e )
{
int iSelected = lbxMaze.SelectedIndex;
bool flagCheckIcomeFromLstBx = true;

if( iSelected >= 0 )
{
MazeItemData item = lbxMaze.Items[ iSelected ] as
MazeItemData;
_currParam = item;
SetMazeGroupControls();
if( Properties.Settings.Default.MarkCurrentMaze )
ValueChanged( false );
}

HandleMazeListButtons();
}

//.... then i test if I come from the listbox or not

private void nudNumMin_ValueChanged(object sender, EventArgs e)
{
if (flagCheckIcomeFromLstBx == false)
{
if (nudNumMin.Value >= nudNumMax.Value)
{
MessageBox.Show("La valeur minimale doit être inférieure
Ã* la valeur maximale.", "Valeur invalide ", MessageBoxButtons.OK);
nudNumMin.Value = nudNumMax.Value - 1;
}

_currParam.GenerationData.NumberMin = (int)nudNumMin.Value;
ValueChanged(true);
}
else
{
_currParam.GenerationData.NumberMin = (int)nudNumMin.Value;
ValueChanged(true);
flagCheckIcomeFromLstBx = false;
}
}

private void nudNumMax_ValueChanged(object sender, EventArgs e)
{
if (flagCheckIcomeFromLstBx == false)
{
if (nudNumMin.Value >= nudNumMax.Value)
{
MessageBox.Show("La valeur minimale doit être inférieure
Ã* la valeur maximale.", "Valeur invalide ", MessageBoxButtons.OK);

nudNumMin.Value = nudNumMax.Value - 1;
}

_currParam.GenerationData.NumberMax = (int)nudNumMax.Value;
ValueChanged(true);
}
else
{
_currParam.GenerationData.NumberMax = (int)nudNumMax.Value;
ValueChanged(true);
flagCheckIcomeFromLstBx = false;
}
}
--
http://www.scalpa.info
http://scalpa98.blogspot.com/
http://scalpa-production.blogspot.com/

Jul 3 '08 #4
On Wed, 02 Jul 2008 23:51:23 -0700, Pascal <sc************@scalpa.info
wrote:
hello Pete

I did this without success.... don't know why... any idea ?
some where at the beginning of the code boolean declaration :
The basic problem is that you are redeclaring the flag as a local variable
in the "lbxMaze_SelectedIndexChanged()" method, hiding the private class
field. So the private class field is never actually changed.

For what it's worth, I wouldn't write "flagCheckIcomeFromLstBx == false".
Just write "!flagCheckIcomeFromLstBx" instead.

Also, I wouldn't actually set the flag in the
"lbxMaze_SelectedIndexChanged()" method, because you don't call
"SetMazeGroupControls()" unless there's actually a selection. When you
wind up with nothing selected, you'll also wind up disabling your
validation for the next time the user actually changes the control value
(assuming they don't change the ListBox selection before that).

Since it's specifically the method "SetMazeGroupControls()" that will
cause the validation to occur, IMHO that's the method in which you should
set the flag.

Pete
Jul 3 '08 #5
Hello Pete

It took me a lot of time to understand the way to do it, but now it works
fine.
Thanks a lot spending time to help me.

here is the code perhaps it can help someone else !

at the beginning of form1.cs
#region variables

private bool flagCheckIcomeFromLstBx = true;

private void nudNumMin_ValueChanged(object sender, EventArgs e)
{
if (flagCheckIcomeFromLstBx == false)
{
if (nudNumMin.Value >= nudNumMax.Value)
{
MessageBox.Show("La valeur minimale doit être inférieure
Ã* la valeur maximale.", "Valeur invalide ", MessageBoxButtons.OK);
nudNumMin.Value = nudNumMax.Value - 1;
}

_currParam.GenerationData.NumberMin = (int)nudNumMin.Value;
ValueChanged(true);
}
else
{
_currParam.GenerationData.NumberMin = (int)nudNumMin.Value;
ValueChanged(true);
flagCheckIcomeFromLstBx = false;
}
}

private void nudNumMax_ValueChanged(object sender, EventArgs e)
{
if (flagCheckIcomeFromLstBx == false)
{
if (nudNumMin.Value >= nudNumMax.Value)
{
MessageBox.Show("La valeur minimale doit être inférieure
Ã* la valeur maximale.", "Valeur invalide ", MessageBoxButtons.OK);

nudNumMin.Value = nudNumMax.Value - 1;
}

_currParam.GenerationData.NumberMax = (int)nudNumMax.Value;
ValueChanged(true);
}
else
{
_currParam.GenerationData.NumberMax = (int)nudNumMax.Value;
ValueChanged(true);
flagCheckIcomeFromLstBx = false;
}
}

private void SetMazeGroupControls()
{
_boInitilizing = true;
flagCheckIcomeFromLstBx = true;

// misc
chbNewRow.Checked = _currParam.NewRow;
nudMazeCount.Value = (decimal)_currParam.Count;

// generation
nudMazeWidth.Value =
(decimal)_currParam.GenerationData.CarreWidth;
nudNumMin.Value = (decimal)_currParam.GenerationData.NumberMin;
nudNumMax.Value = (decimal)_currParam.GenerationData.NumberMax;
nudCellSize.Value = (decimal)_currParam.ExerciseData.CellSize;

// Exercise parameters
chbExerciceShowCible.Checked =
_currParam.ExerciseData.ShowCible;
pnlExerciceCibleColor.BackColor =
_currParam.ExerciseData.CibleColor;
chbExerciseShowNumbers.Checked =
_currParam.ExerciseData.ShowNumbers;
pnlExerciseNumberColor.BackColor =
_currParam.ExerciseData.NumberColor;
chbExerciseShowSolution.Checked =
_currParam.ExerciseData.ShowSolution;
pnlExerciseSolutionColor.BackColor =
_currParam.ExerciseData.SolutionColor;
chbExerciseShowWalls.Checked =
_currParam.ExerciseData.ShowWalls;
nudExerciseWallWidth.Value =
(decimal)_currParam.ExerciseData.WallWidth;

// Solution parameters
chbSolutionShowCible.Checked =
_currParam.SolutionData.ShowCible;
pnlSolutionCibleColor.BackColor =
_currParam.SolutionData.CibleColor;
chbSolutionShowNumbers.Checked =
_currParam.SolutionData.ShowNumbers;
pnlSolutionNumberColor.BackColor =
_currParam.SolutionData.NumberColor;
chbSolutionShowSolution.Checked =
_currParam.SolutionData.ShowSolution;
pnlSolutionSolutionColor.BackColor =
_currParam.SolutionData.SolutionColor;
chbSolutionShowWalls.Checked =
_currParam.SolutionData.ShowWalls;
nudSolutionWallWidth.Value =
(decimal)_currParam.SolutionData.WallWidth;

_boInitilizing = false;
}

All the code is from daniel marcel Camenzind who made a beautiful and handy
soft that save me a lot of time in my job see here "labyrinthales"
http://www.scalpa.info/new_logiciels.php and for fun and learning C# i try
to clone it to do another soft "Carrés magiques".
Thanks to both of you sharing your knowledge.
pascal

Jul 5 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nilz | last post by:
Hi Guys, Do anyone know how to change the BorderStyle of the selected row . I tried using the Band Property of the UltraGrid but the change is applied to each and every Cell in the Grid. Anybody...
3
by: John Walker | last post by:
Hi, On an ASP.NET page I have a drop down list control. When the user pulls down the list and makes a selection, I perform validation, and if the validation fails I want the selected item in...
6
by: Shelly | last post by:
OK, I am at a toral loss after having programmed for forty years. Here are my results: selHint_2=1 It is clear that for the second time through the loop ($i=1) that $index=1 and $selHint_2=1,...
5
by: Dick | last post by:
I have a GridView bound to an ObjectDataSource. I have a Button that calls GridView.DataBind. I want the row that is selected before the DataBind to still be selected afterwards. This happens...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.