Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
I have a custom forms grid control that has a collection property which contains object which has two string properties set to be localized. This works as expected, except the Name (the key) used in the .resx file is too generic. As an example, it will assign the Name to be resource.Label, resource.Label1, resource.Label2. This becomes a problem when an entry is added to the collection as everything is shifted and therefore incorrect values are resolved from the .resx file.

Is there any way to hook into the .resx writing process and in that way customize the key (the value used in the Name field)? I am hoping to be able to set this to be the grid's name + field name (the collection is basically a collection of fields), e.g. grdOrder.OrdNum.Label.

Thanks in advance,

Trausti

Looks like I did not explain the situation clearly enough.

Here is the collection property in the grid:

VB
Description("Collection of Column Info objects"), _
Category("Oppenheimer Properties"), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public ReadOnly Property ColumnInfo() As ColumnInfoCollection
    Get
        If columnInfos Is Nothing Then
            columnInfos = New ColumnInfoCollection
        End If
        Return columnInfos
    End Get
End Property


This collection contains objects which are made up of key (string) and another object called DataLink. The DataLink object contains number of properties, of which one is localized:

VB
Description("Label of the field"), _
DefaultValue(""), _
Localizable(True), _
Category("Oppenheimer Properties"), _
NotifyParentProperty(True)> _
Property Label() As String
    Get
        Return lbl
    End Get
    Set(ByVal Value As String)
        lbl = Value
    End Set
End Property

Let's say I have 3 DataLink objects in my ColInfo collection. In the .resx file VS will use resource.Label, resource.label1 and resource.label2. This is my problem.

Again, in short, I am asking if somebody knows if, on designer level, I can provide the key used by VS in the .resx files.
Posted
Updated 9-Sep-13 8:04am
v2

1 solution

I think you are going in a wrong direction. You should never use, say, label names "Label", "Label1", "Label2" or the like. Such name violate (good) Microsoft naming conventions which don't allow, in particular, digits, underscores and abbreviations in any names, for some really good reasons. All names should be properly spelled and be semantically sensitive. If you follow these conventions, you won't face problems with resource names as well.

By the way, many names violating those conventions are generated by the designer. It's only natural: the designer "knows" nothing about your semantic. But why do you think Visual Studio provides a refactoring engine for? With the designer, those "wrong" names are even convenient: when you see such name, it indicates that you did not touch those objects yet and they are still need attention. Rename them using the refactoring engine as you come to using such objects.

—SA
 
Share this answer
 
v2
Comments
trasi 9-Sep-13 16:57pm    
It's amazing somebody can type two full paragraphs that are so void of content or direction. I am all for listening to an idea that takes me down a different path, but refactoring every form is not about what I am going to do.
Sergey Alexandrovich Kryukov 9-Sep-13 17:03pm    
It simply means that you are lost due to some past mistake and don't want to admit it. It's a good advice which you should better follow. If you think that instead of clearing the trash you should create another layer of trash to cover already created trash, go ahead. It's very frustrating to give an advice and face such attitude. However, you decide...
—SA
trasi 9-Sep-13 17:20pm    
Your original reply was loaded with arrogance and not helpful at all. This last comment of yours just underlines that. I am looking for a sensible solution to a very real problem. I have no issue with going back to all my designers and re-write them, if that's what it would take.

But we are talking about designer generated code here. I have no idea how one would go about "refactoring" designer generated code. And your "solution" gave no hint of that or link to anything useful.
Sergey Alexandrovich Kryukov 9-Sep-13 17:26pm    
(Sigh...) This is your "have no idea", not others. If you have some technical arguments, then argue, not lower down to personal characteristics. If you got no hint, this is your problem, but, to solve it, you could at least ask some questions. Do you need a resolution, a magic trick, or a confirmation that you did it all right? :-)
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900