473,770 Members | 6,978 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 SetMazeGroupCon trols()
{
_boInitilizing = true;

// misc
chbNewRow.Check ed = _currParam.NewR ow;
nudMazeCount.Va lue = (decimal)_currP aram.Count;

// generation
nudMazeWidth.Va lue =
(decimal)_currP aram.Generation Data.CarreWidth ;
nudNumMin.Value = (decimal)_currP aram.Generation Data.NumberMin;
nudNumMax.Value = (decimal)_currP aram.Generation Data.NumberMax;
nudCellSize.Val ue = (decimal)_currP aram.ExerciseDa ta.CellSize;
.......

private void lbxMaze_Selecte dIndexChanged( object sender, EventArgs e )
{
int iSelected = lbxMaze.Selecte dIndex;

if( iSelected >= 0 )
{
MazeItemData item = lbxMaze.Items[ iSelected ] as
MazeItemData;
_currParam = item;
SetMazeGroupCon trols();
if( Properties.Sett ings.Default.Ma rkCurrentMaze )
ValueChanged( false );
}

HandleMazeListB uttons();
}

........
private void nudNumMin_Value Changed(object sender, EventArgs e)
{

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

nudNumMin.Value = nudNumMax.Value - 1;
}

_currParam.Gene rationData.Numb erMin = (int)nudNumMin. Value;
ValueChanged(tr ue);
}

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

nudNumMax.Value = nudNumMin.Value + 1;
}
_currParam.Gene rationData.Numb erMax = (int)nudNumMax. Value;
ValueChanged(tr ue);
}
http://www.scalpa.info

Jul 2 '08 #1
5 1412
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 flagCheckIcomeF romLstBx = 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_Selecte dIndexChanged( object sender, EventArgs e )
{
int iSelected = lbxMaze.Selecte dIndex;
bool flagCheckIcomeF romLstBx = true;

if( iSelected >= 0 )
{
MazeItemData item = lbxMaze.Items[ iSelected ] as
MazeItemData;
_currParam = item;
SetMazeGroupCon trols();
if( Properties.Sett ings.Default.Ma rkCurrentMaze )
ValueChanged( false );
}

HandleMazeListB uttons();
}

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

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

_currParam.Gene rationData.Numb erMin = (int)nudNumMin. Value;
ValueChanged(tr ue);
}
else
{
_currParam.Gene rationData.Numb erMin = (int)nudNumMin. Value;
ValueChanged(tr ue);
flagCheckIcomeF romLstBx = false;
}
}

private void nudNumMax_Value Changed(object sender, EventArgs e)
{
if (flagCheckIcome FromLstBx == false)
{
if (nudNumMin.Valu e >= nudNumMax.Value )
{
MessageBox.Show ("La valeur minimale doit être inférieure
Ã* la valeur maximale.", "Valeur invalide ", MessageBoxButto ns.OK);

nudNumMin.Value = nudNumMax.Value - 1;
}

_currParam.Gene rationData.Numb erMax = (int)nudNumMax. Value;
ValueChanged(tr ue);
}
else
{
_currParam.Gene rationData.Numb erMax = (int)nudNumMax. Value;
ValueChanged(tr ue);
flagCheckIcomeF romLstBx = 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_Select edIndexChanged( )" method, hiding the private class
field. So the private class field is never actually changed.

For what it's worth, I wouldn't write "flagCheckIcome FromLstBx == false".
Just write "!flagCheckIcom eFromLstBx" instead.

Also, I wouldn't actually set the flag in the
"lbxMaze_Select edIndexChanged( )" method, because you don't call
"SetMazeGroupCo ntrols()" 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 "SetMazeGroupCo ntrols()" 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 flagCheckIcomeF romLstBx = true;

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

_currParam.Gene rationData.Numb erMin = (int)nudNumMin. Value;
ValueChanged(tr ue);
}
else
{
_currParam.Gene rationData.Numb erMin = (int)nudNumMin. Value;
ValueChanged(tr ue);
flagCheckIcomeF romLstBx = false;
}
}

private void nudNumMax_Value Changed(object sender, EventArgs e)
{
if (flagCheckIcome FromLstBx == false)
{
if (nudNumMin.Valu e >= nudNumMax.Value )
{
MessageBox.Show ("La valeur minimale doit être inférieure
Ã* la valeur maximale.", "Valeur invalide ", MessageBoxButto ns.OK);

nudNumMin.Value = nudNumMax.Value - 1;
}

_currParam.Gene rationData.Numb erMax = (int)nudNumMax. Value;
ValueChanged(tr ue);
}
else
{
_currParam.Gene rationData.Numb erMax = (int)nudNumMax. Value;
ValueChanged(tr ue);
flagCheckIcomeF romLstBx = false;
}
}

private void SetMazeGroupCon trols()
{
_boInitilizing = true;
flagCheckIcomeF romLstBx = true;

// misc
chbNewRow.Check ed = _currParam.NewR ow;
nudMazeCount.Va lue = (decimal)_currP aram.Count;

// generation
nudMazeWidth.Va lue =
(decimal)_currP aram.Generation Data.CarreWidth ;
nudNumMin.Value = (decimal)_currP aram.Generation Data.NumberMin;
nudNumMax.Value = (decimal)_currP aram.Generation Data.NumberMax;
nudCellSize.Val ue = (decimal)_currP aram.ExerciseDa ta.CellSize;

// Exercise parameters
chbExerciceShow Cible.Checked =
_currParam.Exer ciseData.ShowCi ble;
pnlExerciceCibl eColor.BackColo r =
_currParam.Exer ciseData.CibleC olor;
chbExerciseShow Numbers.Checked =
_currParam.Exer ciseData.ShowNu mbers;
pnlExerciseNumb erColor.BackCol or =
_currParam.Exer ciseData.Number Color;
chbExerciseShow Solution.Checke d =
_currParam.Exer ciseData.ShowSo lution;
pnlExerciseSolu tionColor.BackC olor =
_currParam.Exer ciseData.Soluti onColor;
chbExerciseShow Walls.Checked =
_currParam.Exer ciseData.ShowWa lls;
nudExerciseWall Width.Value =
(decimal)_currP aram.ExerciseDa ta.WallWidth;

// Solution parameters
chbSolutionShow Cible.Checked =
_currParam.Solu tionData.ShowCi ble;
pnlSolutionCibl eColor.BackColo r =
_currParam.Solu tionData.CibleC olor;
chbSolutionShow Numbers.Checked =
_currParam.Solu tionData.ShowNu mbers;
pnlSolutionNumb erColor.BackCol or =
_currParam.Solu tionData.Number Color;
chbSolutionShow Solution.Checke d =
_currParam.Solu tionData.ShowSo lution;
pnlSolutionSolu tionColor.BackC olor =
_currParam.Solu tionData.Soluti onColor;
chbSolutionShow Walls.Checked =
_currParam.Solu tionData.ShowWa lls;
nudSolutionWall Width.Value =
(decimal)_currP aram.SolutionDa ta.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 "labyrintha les"
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
10315
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 if know anything plz tell me. Thanks Nilz ___ Newsgroups brought to you courtesy of www.dotnetjohn.com
3
2996
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 the drop down box to go back to what the value was before the user tried to change it, but at that point I will not know what the original value was. Or is there a drop down control "revert" method, or is there any way of knowing what the original...
6
1461
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, while for the first pass through ($i=0) $index=0 and $selHint=1. Yet, the " selected " comes up for the first time and not for the second. It should be the other way around. Any clues?
5
4838
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 automatically if the data doesn't change. But if records have been added or deleted then it looks as if some code is necessary: I've done this by using GridView.SelectedValue to get the key value of the currently selected Row and then by itterating...
11
5815
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
0
9591
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10228
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8883
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3970
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3575
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.