Click here to Skip to main content
13,355,018 members (59,620 online)
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 23 Nov 2004

Localizable DataSet

, 23 Nov 2004
Rate this:
Please Sign up or sign in to vote.
Put language-dependent column captions in the DataSet itself and use it in your code wherever you need it!


The .NET Framework has great support for multi-language applications. You can put all your translated form text in resource files. What happens when you bind a DataSet to a grid? In our case, we use Component One's TrueDBGrid. If you make a form localizable, all the formatting of the grid becomes language-dependent. It would be great to make only the columns' captions language-dependent. Then, the next problem arises: you have to maintain all the forms. It would make more sense to put the translations of the data fields' captions in the DataSet definition itself. And that's what I have made, using an adapted version of Shawn Wildermuth's DataSet Generator.


First, read my previous article on Inherited DataSets. The version of the DataSet Generator with this article is basically a further developed version.

The magic is done with this piece of generated code:

Public Overridable Property Localizable() As Boolean
    Return Me._Localizable
  End Get
  Set(ByVal Value As Boolean)
    _Localizable = value
    If value Then
      Dim resourceManager As System.Resources.ResourceManager = New 
      Dim tableIndex As Integer
      Dim columnIndex As Integer
      Dim caption As String
      tableIndex = 0
      Do While (tableIndex < Me.Tables.Count)
        columnIndex = 0
        Do While (columnIndex < Me.Tables(tableIndex).Columns.Count)
            caption = resourceManager.GetString( _
              String.Join(".", New String()_
              {Me.Tables(tableIndex).TableName, _
               Me.Tables(tableIndex).Columns(columnIndex).ColumnName, "Caption"}))
          Catch ex As System.Exception
          End Try
          If (Not (caption) Is Nothing) Then
            Me.Tables(tableIndex).Columns(columnIndex).Caption = caption
          End If
          columnIndex = (columnIndex + 1)
      tableIndex = (tableIndex + 1)
    End If
  End Set
End Property

All you have to do to make the Caption property language dependent, is put the translations in .resx files with the same name as the DataSet's generated code file. If your DataSet's XSD is called DataSet1.xsd, the generated code file will be called DataSet1.vb (if you're working on a VB.NET project). The files you have to add to your project must be named DataSet1.vb.resx,, etc. To give you a good start, I put a little routine in the test project that creates these files for you and fills it with all the columns' captions. Just press the button on the correct form.

The choice is yours!

Of course, you don't want to translate all captions all the time. Accessing resource files may create unnecessary overhead. First, if you leave out Caption translations from the resource files, no translation work will be done. Second, as long as you don't set the Localizable property to True (e.g. from the Form Designer in Visual Studio), no translation work is done at all.

Other options

Wout de Zeeuw proposed translating object properties so they would display correctly in a PropertyGrid. I spent some time trying to port this Attribute centered approach to the DataSet, but it gave me too many headaches. If you want to use the .NET PropertyGrid, my solution may not be the best one.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Software Developer
Netherlands Netherlands
My first encounters with computers where Sinclair, TI99-4A, C64, Apple II. Have programmed ever since. Worked for a few logistic companies.
I have been a VB.NET programmer for quite some years. I work with a small firm, that specializes in supply chain planning for bulk products. We have our own application, Delivery+, that helps vehicle planners with their daily job.
I am married and I have two children. I am building an eco-friendly house and try to live green.

You may also be interested in...


Comments and Discussions

Generalhelp Pin
sreejith ss nair18-Sep-05 22:16
membersreejith ss nair18-Sep-05 22:16 
AnswerRe: help Pin
Pinx20-Sep-05 23:03
memberPinx20-Sep-05 23:03 
QuestionDataGridView i GridView(DevXpress) Pin
winx23-Aug-07 21:28
memberwinx23-Aug-07 21:28 
GeneralRe: help Pin
Stonkie15-Jul-08 12:44
memberStonkie15-Jul-08 12:44 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 23 Nov 2004
Article Copyright 2004 by pinx
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid