Click here to Skip to main content
15,909,742 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
 private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            string tabName = (sender as Button).CommandParameter.ToString();
 
            var item = tabDynamic.Items.Cast<TabItem>().Where(i => i.Name.Equals(tabName)).SingleOrDefault();
 

            TabItem tab = item as TabItem;
 
            if (tab != null)
            {
                if (_tabItems.Count < 3)
                {
                    MessageBox.Show("Cannot remove last tab.");
                }
                else if (MessageBox.Show(string.Format("Are you sure you want to remove the tab '{0}'?", tab.Header.ToString()),
                    "Remove Tab", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    // get selected tab
                    TabItem selectedTab = tabDynamic.SelectedItem as TabItem;
 
                    // clear tab control binding
                    tabDynamic.DataContext = null;
 
                    _tabItems.Remove(tab);
 
                    // bind tab control
                    tabDynamic.DataContext = _tabItems;
 
                    // select previously selected tab. if that is removed then select first tab
                    if (selectedTab == null || selectedTab.Equals(tab))
                    {
                        selectedTab = _tabItems[0];
                    }
                    tabDynamic.SelectedItem = selectedTab;
                }
            }
        }
    }
}


What I have tried:

I want to use C# code in VB.net as above please some one help me
Posted
Updated 24-Oct-16 6:02am
Comments
F-ES Sitecore 24-Oct-16 11:14am    
Google "c# vb.net code converter"

1 solution

You can't mix languages within a single project, although you can reference Assemblies regardless of what language they were written in.
But you can use automated translators to convert between them: Code Converter[^] isn;t too bad. Be aware that it may not get it right, so you should really understand both languages when you test this, and be aware that unless the "source" of that code is targeting the same environment your code is that may not work at all.

Generally speaking, you are better off writing your own code than relying on code you found on the internet and translating it.
 
Share this answer
 
Comments
karim sorathiya 25-Oct-16 5:17am    
thanks alot for your response I understand that I must not mix languages, I am not that good at C# and this code I got from internet and I manage to add new tab and close tab but I am failing to work on cast(of ) in Vb if its possible may be you can help me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900