Solved

Need help Convert VB.NET code

Posted on 2011-09-14
12
463 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A short article about a problem I had getting the GPS LocationListener working.
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 fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now