none
How to change the list separater in regional settings via .NET RRS feed

  • Question

  • Hi,

    Hopefully the write forum.

    I am writing some interop code for MS Project 2007. The issue i have is that you are allowed to have comma's in the project names. This causes an issue when i am inserting a project into another project as the command to do this used the culture info list separator to split the input. In UK setting this is a comma.

    I have manually changed this in regional settings to be a semi colon and this resolves my issue.  Without knowing what problems this may cause i want to be able to adjust the setting only when i need to.

    So how can i change the list separator value in some c# code. I have spent ages looking online but cannot find any examples other than i should use the SetLocalInfo method. But i have no idea how to implement this or what values to pass it.


    Thanks in advance

    Paul

    Friday, December 4, 2009 10:19 AM

Answers

  • Hi Paul,

    I think it's quite an overkill to change the system's list serparator char just to accomodate your design, but it's your decision:

        class Native
        {
            [DllImport("kernel32.dll", SetLastError = true)]
            static extern int SetLocaleInfo(int Locale, int LCType, string lpLCData);
            const int LOCALE_SYSTEM_DEFAULT = 0x800;
            const int LOCALE_SLIST = 0x0000000C;
    
            [DllImport("user32.dll", CharSet = CharSet.Auto)]
            static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, [MarshalAs(UnmanagedType.LPStr)] string lParam);
            static IntPtr HWND_BROADCAST = new IntPtr(0xffff);
            const UInt32 WM_SETTINGCHANGE = 0x001A;
    
            public static void SetSystemListSepartor(string separator)
            {
                SetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SLIST, separator);
                SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, IntPtr.Zero, "");
            }
        }
    


    Marcel
    Friday, December 4, 2009 12:01 PM

All replies

  • Hi Paul,

    I think it's quite an overkill to change the system's list serparator char just to accomodate your design, but it's your decision:

        class Native
        {
            [DllImport("kernel32.dll", SetLastError = true)]
            static extern int SetLocaleInfo(int Locale, int LCType, string lpLCData);
            const int LOCALE_SYSTEM_DEFAULT = 0x800;
            const int LOCALE_SLIST = 0x0000000C;
    
            [DllImport("user32.dll", CharSet = CharSet.Auto)]
            static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, [MarshalAs(UnmanagedType.LPStr)] string lParam);
            static IntPtr HWND_BROADCAST = new IntPtr(0xffff);
            const UInt32 WM_SETTINGCHANGE = 0x001A;
    
            public static void SetSystemListSepartor(string separator)
            {
                SetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SLIST, separator);
                SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, IntPtr.Zero, "");
            }
        }
    


    Marcel
    Friday, December 4, 2009 12:01 PM
  • Thanks Marcel!

    Hello Paul, could you please update us about the result of the suggestion?
    Regards,
    Jialiang Ge
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, December 15, 2009 11:10 AM
    Moderator