CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2003
    Posts
    108

    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) ?

  2. #2
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    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

  3. #3
    Join Date
    Apr 2003
    Posts
    108

    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).

  4. #4
    Join Date
    Nov 2005
    Posts
    63

    Re: big difference with c++ with simple equal operator

    I think you're going to have to post the whole code.

  5. #5
    Join Date
    Oct 2005
    Location
    Islamabad, Pakistan
    Posts
    1,277

    Re: big difference with c++ with simple equal operator

    can u state what do u want to do.

  6. #6
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    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.

  7. #7
    Join Date
    Oct 2005
    Location
    Islamabad, Pakistan
    Posts
    1,277

    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

  8. #8
    Join Date
    Apr 2003
    Posts
    108

    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
  •  





Click Here to Expand Forum to Full Width

Featured