How to check RadTabControl's SelectedIndex null or not in WPF

173 views Asked by At

I have the following function:

private void UserDetailTabControl_SelectionChanged(object sender, RadSelectionChangedEventArgs e)
{                        
    RadTabControl obj = sender as RadTabControl;

    if (obj.SelectedIndex != null)

But obj.SelectedIndex != null is giving me warning. The result of the expression is always 'true' since a value of type 'int' is never equal to 'null' of type 'int?'

So how to solve this warning?

1

There are 1 answers

0
123 456 789 0 On

Why you need to check the SelectedIndex for, why not SelectedItem? To answer your question, SelectedIndex is of type int so the default value of SelectedIndex for TabControl should be -1/0 depending on the control that you are using. Thus, you cannot do

obj.SelectedIndex != null,

you can do

obj.SelectedIndex < 0 

for check.