Solved

Need help Convert VB.NET code

Posted on 2011-09-14
12
472 Views
Last Modified: 2012-05-12

Hello,

How can help me to convert this string to a public shared sub?

Form1.Ultragrid1.DisplayLayout.Bands(0).Columns

I've already 2 string with the information.
FormName as String
Grid as String



0
Comment
Question by:prinsbj
  • 6
  • 6
12 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 36536713
Try something like:
Public Shared Sub Foo(ByVal FormName As String, ByVal GridName As String)
        Dim frm As Form = Application.OpenForms(FormName)
        If Not IsNothing(frm) Then
            Dim ctls() As Control = frm.Controls.Find(GridName, True)
            If ctls.Length > 0 AndAlso TypeOf ctls(0) Is UltraGrid Then
                Dim grid As UltraGrid = CType(ctls(0), UltraGrid)
                ' ... do something with "grid" ...
            End If
        End If
    End Sub

Open in new window

0
 

Author Comment

by:prinsbj
ID: 36538351
Hello Idle_Mind,

Here the code I use.

Now I've to change something in the code for the formname "MaterialInward" and for the "UltraGrid1" this must be variable.

Hope it's now more clear.

Thanks
For Each col In MaterialInward.UltraGrid1.DisplayLayout.Bands(0).Columns
                    If Len(LocRM.GetString(col.Key.ToString)) >= 1 Then
                        col.Header.Caption = LocRM.GetString(col.Key.ToString)
                    Else
                    End If
                Next

Open in new window

0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 36538729
Right...so at line #7 where I have { ... do something with "grid" ... }, you could do:

                For Each col In grid.DisplayLayout.Bands(0).Columns
                    If Len(LocRM.GetString(col.Key.ToString)) >= 1 Then
                        col.Header.Caption = LocRM.GetString(col.Key.ToString)
                    Else
                    End If
                Next

And you'd call Foo() like this:

    Foo("MaterialInward", "UltraGrid1")
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:prinsbj
ID: 36538992
"MaterialInward", "UltraGrid1" should be variable and are now avaliable as strings.

So how can I do this?
0
 

Author Comment

by:prinsbj
ID: 36539077
This is the complet Public Shared Sub code.

I call this Public Shared Sub on this way:

        CWSProps.sub_FillLanguage(Me, Me.Name)

Hope you can give me a script that Replace the text MaterialInward and UltraGrid1.

Thanks!
Public Shared Sub sub_FillLanguage(ByVal Page As Control, ByVal FormName As String)

        For Each ctrl As Control In Page.Controls

            If TypeOf ctrl Is UltraExpandableGroupBox Then
                If Len(LocRM.GetString(ctrl.Name.ToString)) >= 1 Then
                    DirectCast(ctrl, UltraExpandableGroupBox).Text = LocRM.GetString(ctrl.Name.ToString)
                Else
                End If
            Else
            End If

            If TypeOf ctrl Is UltraLabel Then
                If Len(LocRM.GetString(ctrl.Name.ToString)) >= 1 Then
                    DirectCast(ctrl, UltraLabel).Text = LocRM.GetString(ctrl.Name.ToString)
                Else
                End If
            End If

            If TypeOf ctrl Is UltraButton Then
                If Len(LocRM.GetString(ctrl.Name.ToString)) >= 1 Then
                    DirectCast(ctrl, UltraButton).Text = LocRM.GetString(ctrl.Name.ToString)
                Else
                End If
            End If

            If TypeOf ctrl Is UltraGrid Then
                Dim col As UltraGridColumn
                For Each col In MaterialInward.UltraGrid1.DisplayLayout.Bands(0).Columns
                    If Len(LocRM.GetString(col.Key.ToString)) >= 1 Then
                        col.Header.Caption = LocRM.GetString(col.Key.ToString)
                    Else
                    End If
                Next
            End If



            If ctrl.Controls.Count > 0 Then
                sub_FillLanguage(ctrl, FormName)
            End If
        Next
    End Sub

Open in new window

0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 36539086
Seriously?...  =\

    Dim frmName As String = "MaterialInward"
    Dim gridName As String = "UltraGrid1"
    Foo(frmName, gridName)
0
 

Author Comment

by:prinsbj
ID: 36539205
I do not understand what you are saying.

Is there not a each command/code that I can fill in on the place of MaterialInwards and UltraGrid1?

Thanks
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 36539615
I don't understand either...

You're passing in:

    Public Shared Sub sub_FillLanguage(ByVal Page As Control, ByVal FormName As String)

And the line in question is:

                For Each col In MaterialInward.UltraGrid1.DisplayLayout.Bands(0).Columns

How do "Page", "FormName", "MaterialInward" and "UltraGrid1" relate to each other?...

You need to convert "FormName" to the Form instance called "MaterialInward"?
Where would "UltraGrid1" come from?...are you going to pass that in to so it becomes?

    Public Shared Sub sub_FillLanguage(ByVal Page As Control, ByVal FormName As String, ByVal GridName As String)
0
 

Author Comment

by:prinsbj
ID: 36539664
The following must be happen.

The FormName is passed to the Public shared Sub  (ByVal Page As Control, ByVal FormName As String)

The UltraGrid1 name Should be GridName.String I can get from the Page as Control.Name

So now I need to change my  line

For Each col In FormName.GridName.DisplayLayout.Bands(0).Columns

But this does not work!

0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 36539771
I don't quite understand this statement:

    "The UltraGrid1 name Should be GridName.String I can get from the Page as Control.Name"

So you're saying that the grid name should be the name of the current control in the loop?

    For Each ctrl As Control In Page.Controls
        ' ctrl.Name --> GridName?

If yes, try something like this:
Public Shared Sub sub_FillLanguage(ByVal Page As Control, ByVal FormName As String)

        Dim frm As Form = Application.OpenForms(FormName)
    
        For Each ctrl As Control In Page.Controls

            ....

            If TypeOf ctrl Is UltraGrid Then

                If Not IsNothing(frm) Then
                    Dim ctls() As Control = frm.Controls.Find(ctrl.Name, True)
                    If ctls.Length > 0 AndAlso TypeOf ctls(0) Is UltraGrid Then
                        Dim grid As UltraGrid = CType(ctls(0), UltraGrid)

                        For Each col As UltradGridColumn In grid.DisplayLayout.Bands(0).Columns
                            If Len(LocRM.GetString(col.Key.ToString)) >= 1 Then
                                col.Header.Caption = LocRM.GetString(col.Key.ToString)
                            Else
                            End If
                        Next

                    End If
                End If

            End If

Open in new window

0
 

Author Closing Comment

by:prinsbj
ID: 36539796
Idle_Mind

Thank you. This code works for me perfect.

Super!!!!
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 36539799
Yay!  =)
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question