Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference DataGridViewColumn.HeaderText manually in resources files?

Tags:

c#

winforms

For transaction purposes, I created resources files which replace text property of my winforms components.

However, it seems i can't correctly reference my DataGridViewColumn.HeaderText property manually in the resources file; but I can change the HeaderText property of it in the code, but not in the resource file (it works for other components...)

I've also tried :

DataGridViewColumn.HeaderText = "test1";
DataGridViewColumn.HeaderCell.Value = "test2";
DataGridView.Columns[1].HeaderText = "test3";

The code works when calling it but not when I put it in the resources file.

like image 557
Théo Avatar asked Dec 19 '25 16:12

Théo


1 Answers

If you are using satellite assemblies for keeping localized text then you can do something like this :

//namespacaes to be imported at the top of your code file
using System.Resources;
using System.Reflection; 

//source code for your method
ResourceManager resourceManager = new ResourceManager("TestSatelliteAssembly.Resources.LocalizedResources",Assembly.GetExecutingAssembly());
DataGridViewColumn.HeaderText = resourceManager.GetString("lblUserNameText");

lblUserNameText is the key for the text you are trying to localize. TestSatelliteAssembly is the name of your satellite assembly.

You can read more about satellite assemblies in my blog here.

like image 107
RBT Avatar answered Dec 24 '25 11:12

RBT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!