in

vbCity Blogs

New (temp) place for vbCity Blogs

Mike McIntyre's .NET Journal

April 2009 - Posts

  • Country List for ComboBox or DropDown from .NET Globalization Namespace

     Source Code: Country ListView From .NET Globalization Namespace

     

    Country ListView From .NET Globalization Namespace

     

    This code demonstrates how to use the CultureInfo and RegionInfo classes from the .NET Globalization namespace to create a SortedDictionary list that can be bound to a ComboBox or DropDownList.

     

    Visual Basic 2005

     

    Imports System.Collections.Generic

    Imports System.Globalization

     

    Public Class Countries

        Public Shared Function GetCounties() As SortedDictionary(Of String, String)

     

            Dim countryList As New SortedDictionary(Of String, String)

            ' Iterate the Framework Cultures...

            For Each ci As CultureInfo In CultureInfo.GetCultures(CultureTypes.FrameworkCultures)

                Dim ri As RegionInfo

                Try

                    ri = New RegionInfo(ci.Name)

                Catch

                    ' If a RegionInfo object could not be created we don't want to use the CultureInfo

                    '    for the country list.

                    Continue For

                End Try

                ' Create new country dictionary entry.

                Dim newKeyValuePair As New KeyValuePair(Of String, String)(ri.EnglishName, ri.ThreeLetterISORegionName)

     

                ' If the country is not alreayd in the countryList add it...

                If Not countryList.ContainsKey(ri.EnglishName) Then

                    countryList.Add(newKeyValuePair.Key, newKeyValuePair.Value)

                End If

            Next

     

            Return countryList

        End Function

    End Class

     

     

    C# 2005

     

    using System;

    using System.Collections.Generic;

    using System.Text;

    using System.Globalization;

     

    public class Countries

    {

        public static SortedDictionary<string, string> GetCounties()

        {

     

            SortedDictionary<string, string> countryList = new SortedDictionary<string, string>();

            // Iterate the Framework Cultures...

            foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.FrameworkCultures))

            {

                RegionInfo ri = null;

                try

                {

                    ri = new RegionInfo(ci.Name);

                }

                catch

                {

                    // If a RegionInfo object could not be created we don't want to use the CultureInfo

                    //    for the country list.

                    continue;

                }

                // Create new country dictionary entry.

                KeyValuePair<string, string> newKeyValuePair = new KeyValuePair<string, string>(ri.EnglishName, ri.ThreeLetterISORegionName);

     

                // If the country is not alreayd in the countryList add it...

                if (!(countryList.ContainsKey(ri.EnglishName)))

                {

                    countryList.Add(newKeyValuePair.Key, newKeyValuePair.Value);

                }

            }

     

            return countryList;

        }

    }

     

  • Create Word 2003 Documents with .NET

     Source Code: Create Word 2003 Documents with .NET

     

    Create Word 2003 Documents with .NET

     

    While Microsoft Office Word 2003 still relies on VBA and COM, it can be automated in .NET code via .NET and COM interoperability. This allows you to create more powerful applications by integrating the many functions available in the Word products into your application.

    The sample code in the attached projects demonstrates how to do the following: Create a Word application object; create a Word document, insert paragraphs with text and formatting; browse and modify various ranges within a document; insert tables, format tables, and populate the tables with data; and adding a chart.

  • Don't Loose Your Visual Studio Toolbox Settings

     In Visual Studio 2008 you can export your toolbox customizations from Inport/Export Settings wizard. Toolbox is under general settings.

Copyright 1998-2009 vbCity.com LLC
Powered by Community Server (Non-Commercial Edition), by Telligent Systems