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

P

Pascal

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_clickonce/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
 
P

Pascal

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
 
P

Pascal

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;
}
}
 
P

Pascal

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top