[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 512
  • Last Modified:

Need help Convert VB.NET code


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
prinsbj
Asked:
prinsbj
  • 6
  • 6
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
prinsbjAuthor Commented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
prinsbjAuthor Commented:
"MaterialInward", "UltraGrid1" should be variable and are now avaliable as strings.

So how can I do this?
0
 
prinsbjAuthor Commented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Seriously?...  =\

    Dim frmName As String = "MaterialInward"
    Dim gridName As String = "UltraGrid1"
    Foo(frmName, gridName)
0
 
prinsbjAuthor Commented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
prinsbjAuthor Commented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
prinsbjAuthor Commented:
Idle_Mind

Thank you. This code works for me perfect.

Super!!!!
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Yay!  =)
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now