-
June 8th, 2006, 11:47 AM
#1
big difference with c++ with simple equal operator
Hello,
When I do that:
tabControl[2].SelectedIndex is equal to 3 for instance
index_of_selected_tab[2] = tabControl[2].SelectedIndex;
tabControl[2].SelectedIndex = 0;
Then, index_of_selected_tab[2] changes value to 0 !!!!!!!!!
In c++, it should be equal to 3.
How to proceed in order to do like in c++ (if I right understood, I am now transmitting by ref, but I would like to transmit by value) ?
-
June 8th, 2006, 12:10 PM
#2
Re: big difference with c++ with simple equal operator
I'm not able to reproduce your problem and it shouldn't be the way you've described. Maybe you should post your code (or a compilable piece that shows your problem)?
- petter
-
June 8th, 2006, 12:39 PM
#3
Re: big difference with c++ with simple equal operator
Thank you for your answer. Here is the code:
// declare
int[] index_of_selected_tab;
index_of_selected_tab = new int[4];
TabControl[] tabControl;
tabControl = new TabControl[4];
//init
for (i = 0; i < 4; i++)
{
index_of_selected_tab[i] = 0;
tabControl[i] = new TabControl();
}
//later
let's say tabControl[2].SelectedIndex is equal to 3 because I have clicked on the fourth tabpage of tabcontrol[2]
//then when I do this
index_of_selected_tab[2] = tabControl[2].SelectedIndex;
//index_of_selected_tab[2] is now equal to 3 (this makes sence), but when I do this
tabControl[2].SelectedIndex = 0;
//then, index_of_selected_tab[2] changes value to 0 !!!!!!!!!
If not clear, I can send the complete code if possible (just tell me where).
-
June 9th, 2006, 12:55 AM
#4
Re: big difference with c++ with simple equal operator
I think you're going to have to post the whole code.
-
June 9th, 2006, 01:43 AM
#5
Re: big difference with c++ with simple equal operator
can u state what do u want to do.
-
June 9th, 2006, 01:56 AM
#6
Re: big difference with c++ with simple equal operator
Do you set index_of_selected_tab[2] in event handler of SelectionIndexChanged of the TabControl? If so, here is your answer: tabControl[2].SelectedIndex = 0 fires the SelectionIndexChanged event, so the value of index_of_selected_tab is reset. Nothing else is possible. Integer is value type - you cannot pass it by reference, so change of one instance cannot be escaled to another.
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post.
-
June 9th, 2006, 01:56 AM
#7
Re: big difference with c++ with simple equal operator
Code:
tabControl[2].SelectedIndex = 3;
//index_of_selected_tab[2] gets 3
index_of_selected_tab[2] = tabControl[2].SelectedIndex;
//changed selected index to 0
tabControl[2].SelectedIndex = 0;
////index_of_selected_tab[2] show 3
MessageBox.Show(Convert.ToString ( index_of_selected_tab[2]));
so i didn't got into any problem ,there must be problem anywhere else in your complete code
-
June 9th, 2006, 09:53 AM
#8
Re: big difference with c++ with simple equal operator
Thank you for your help. I found the problem.
It is because I create dynamically the tabControl. And when the tabControl is created, this does not really make sence but the event "SelectionIndexChanged" is called. So the index_of_selected_tab were reset. I was thinking the event "SelectionIndexChanged" should be called only when clicking on a tabPage.
So the solution I found was to save again the index_of_selected_tab under another name before re-creating the tabControl. I am not sure this is the best way but it works.
Thank you again.
Last edited by efkefk; June 9th, 2006 at 09:57 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|