Click here to Skip to main content
15,916,019 members
Home / Discussions / C#
   

C#

 
QuestionWinForm - Localize DataGridView with automatical generated columns Pin
Mc_Topaz3-Nov-20 23:08
Mc_Topaz3-Nov-20 23:08 
Hi!

I have a DataGridView in a Windows Form application where I want to localize the columns in the DataGridView. I use the DataGridView 's DataSource property to populate the DataGridView from a list. Therefore the columns in the DataGridView are genereated automatically after the properies in the list.

Here is the code to populate the DataGridView.
C#
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        var p1 = new Person() { Name = "Foo", Age = 1337 };
        var p2 = new Person() { Name = "Bar", Age = 42 };
        var people = new List<Person>() { p1, p2 };
        dataGridView1.DataSource = people;
    }
}

public class Person
{
    public string Name { get; set; }
    public int Age { get; set; }
}
The generated columns in the DataGridView are Name and Age, the same as the properties in the Person class.


I have set the Form's Localizable property to True.
With a Label in the Form, I have verified that I can change the Label's Text property to different values based on the CurrentCulture / CurrentUICulture I set. I switch between different cultures in the Program.cs file:
C#
static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        var eng = "en";
        var swe = "sv-SE";
        var culture = eng;
        Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(culture);
        Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(culture);

        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }
}
My project have generated Form1.resx and Form1.sv.resx files to handle both English and Swedish. In these files I can find the label's text for the English and Swedish languages accordingly.

I just don't know how to set the DataGridView's column to different languages. Since the columns are not manually created by me I don't have the appropriate values in the Form1.resx and Form1.sv.resx to set the columns based on the selected language.

Is there any solution to this?
AnswerRe: WinForm - Localize DataGridView with automatical generated columns Pin
BillWoodruff4-Nov-20 2:35
professionalBillWoodruff4-Nov-20 2:35 
QuestionCsharp InTheHand.Net read bluetooth data on received event Pin
nowis773-Nov-20 8:07
nowis773-Nov-20 8:07 
AnswerRe: Csharp InTheHand.Net read bluetooth data on received event Pin
jsc423-Nov-20 10:33
professionaljsc423-Nov-20 10:33 
GeneralRe: Csharp InTheHand.Net read bluetooth data on received event Pin
nowis7710-Nov-20 21:01
nowis7710-Nov-20 21:01 
QuestionBusiness Layer Question Pin
Kevin Marois2-Nov-20 6:31
professionalKevin Marois2-Nov-20 6:31 
AnswerRe: Business Layer Question Pin
Richard Deeming2-Nov-20 6:45
mveRichard Deeming2-Nov-20 6:45 
GeneralRe: Business Layer Question Pin
Kevin Marois2-Nov-20 7:27
professionalKevin Marois2-Nov-20 7:27 
Questionuse connection from login form in other forms Pin
Newkid on the block31-Oct-20 5:43
Newkid on the block31-Oct-20 5:43 
AnswerRe: use connection from login form in other forms Pin
OriginalGriff31-Oct-20 5:57
mveOriginalGriff31-Oct-20 5:57 
GeneralRe: use connection from login form in other forms Pin
Newkid on the block31-Oct-20 10:21
Newkid on the block31-Oct-20 10:21 
GeneralRe: use connection from login form in other forms Pin
Dave Kreskowiak31-Oct-20 11:26
mveDave Kreskowiak31-Oct-20 11:26 
AnswerRe: use connection from login form in other forms Pin
Dave Kreskowiak31-Oct-20 6:30
mveDave Kreskowiak31-Oct-20 6:30 
AnswerRe: use connection from login form in other forms Pin
BillWoodruff1-Nov-20 15:12
professionalBillWoodruff1-Nov-20 15:12 
GeneralRe: use connection from login form in other forms Pin
Newkid on the block3-Nov-20 5:45
Newkid on the block3-Nov-20 5:45 
GeneralRe: use connection from login form in other forms Pin
BillWoodruff3-Nov-20 14:46
professionalBillWoodruff3-Nov-20 14:46 
QuestionCrystal reports and datagridviews Pin
Damir Djordjevic31-Oct-20 4:39
Damir Djordjevic31-Oct-20 4:39 
AnswerRe: Crystal reports and datagridviews Pin
Gerry Schmitz31-Oct-20 5:15
mveGerry Schmitz31-Oct-20 5:15 
QuestionIF Else statement on background colour of label. Pin
Member 1497767230-Oct-20 2:29
Member 1497767230-Oct-20 2:29 
SuggestionRe: IF Else statement on background colour of label. Pin
Richard MacCutchan30-Oct-20 2:36
mveRichard MacCutchan30-Oct-20 2:36 
GeneralRe: IF Else statement on background colour of label. Pin
Member 1497767230-Oct-20 2:47
Member 1497767230-Oct-20 2:47 
GeneralRe: IF Else statement on background colour of label. Pin
OriginalGriff30-Oct-20 2:52
mveOriginalGriff30-Oct-20 2:52 
AnswerRe: IF Else statement on background colour of label. Pin
OriginalGriff30-Oct-20 2:50
mveOriginalGriff30-Oct-20 2:50 
GeneralRe: IF Else statement on background colour of label. Pin
Member 1497767230-Oct-20 3:01
Member 1497767230-Oct-20 3:01 
QuestionAdd treasure to my maze game Pin
Member 1497767229-Oct-20 4:10
Member 1497767229-Oct-20 4:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.