0

I'm running the following code.

int count = tabControl.Items.Count;
int bount = tabControl.SelectedIndex;
tabControl.SelectedIndex = 0;
int dount = tabControl.SelectedIndex;

From there, I learn that I have three tabs and that I'm currently standing on the last one (number 2). After I've set the new value, I learn that the selected index's value is zero.

But the GUI seems to disregard it and stays unchanged.

Does it have to do with the fact that the even comes from a data grid object? Or did I use incorrect syntax?

Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
  • did you check output window *after* then you setup value, if there is any binding error/exception. ? – Tigran Jan 20 '15 at 22:19
  • Are you asking how to select a specific tab programmatically? – NoChance Jan 20 '15 at 22:19
  • @EmmadKareem Yes. And also why the method presented doesn't go in effect. – Konrad Viltersten Jan 20 '15 at 22:20
  • @Tigran Nothing about data grid component. There are some warnings but nothing related to this, as far I understand. – Konrad Viltersten Jan 20 '15 at 22:22
  • 1
    See:http://stackoverflow.com/questions/7929646/how-to-programmaticaly-select-a-tabitem-in-wpf-tabcontrol – NoChance Jan 20 '15 at 22:27
  • Where in your code do you have this? In the form load method? Just trying to see what you are trying to accomplish. – Sean Cox Jan 20 '15 at 22:49
  • @TheShaman I'm double clicking on a grid and then, when that clickaroo is involved, I'm showing an editable tab with the information related to the clickee. The workaround with a delay by a dispatcher worked but still it feels like Iäm **hiding** and issue, not **resolving** it. – Konrad Viltersten Jan 20 '15 at 22:54
  • @EmmadKareem Please post the last answer here. It's a bit different question but it will fit here very well. And you'll get some cool rep on that. We all say we don't care about it. But we all do... :) – Konrad Viltersten Jan 20 '15 at 22:56

1 Answers1

0

One way to programatically select a specific tab (page) in WPF:

Select 2nd tab (zero based collection)

this.tabControl1.SelectedItem = tabControl1.Items[1];   

Select 1st tab (zero based collection)

this.tabControl1.SelectedItem = tabControl1.Items[0];

The SelectedIndex property can tell you about the currently displayed page.

As per your comment, I am really not after the rating, I have no one who cares about my rating :)

NoChance
  • 5,632
  • 4
  • 31
  • 45
  • Oh, right. But you need to add the delaying part about dispatcher too. Because **that** was the part that made **the above** behave. Thanks. – Konrad Viltersten Jan 21 '15 at 06:18