none
VB2005 非指定DataGridView 欄位名稱變更 RRS feed

  • 問題

  • 我想做一個 中文繁簡自動轉換的 表單。 把表單 每個元件的 標題自動做 中文繁簡轉換
    因為我每個表單 都是繼承一個基本表單,因此我在基本表單上 寫以下程式碼
    目前 我可以做到 Label 及 Button 的 text 轉換,
    但是 我一直找不到 表單上 的 datagridview 的欄位標題, 請問 要如何做?
    謝謝

    Imports Microsoft.International.Converters.TraditionalChineseToSimplifiedConverter
     
    Private Sub fmBase_Load(ByVal sender As Object, _
            ByVal e As System.EventArgs) Handles Me.Load

      Dim i As Integer

            For i = 0 To Me.Controls.Count - 1
                '  MsgBox(Me.Controls.Item(i).ToString)
                If Me.Controls.Item(i).GetType.Name = "Label" Or Me.Controls.Item(i).GetType.Name = "Button" Then
                    '  MsgBox(Me.Controls.Item(i).Text)
                    If My.Forms.fmMain.strLang = "TW" Then
                        Me.Controls.Item(i).Text = ChineseConverter.Convert(Me.Controls.Item(i).Text.ToString, ChineseConversionDirection.SimplifiedToTraditional)
                    ElseIf My.Forms.fmMain.strLang = "CN" Then
                        Me.Controls.Item(i).Text = ChineseConverter.Convert(Me.Controls.Item(i).Text.ToString, ChineseConversionDirection.TraditionalToSimplified)
                    End If
               ElseIf Me.Controls.Item(i).GetType.Name = "DataGridView" Then

                    '  MsgBox(Me.Controls.Item(i)..Controls.Item(1).Controls.Count)
                    'MsgBox(Me.Controls.Item(i).Name)
     End If

              
            Next
    2007年12月20日 上午 03:25

解答

  •  

    程式碼區塊

    Imports Microsoft.International.Converters.TraditionalChineseToSimplifiedConverter
     
    Private Sub fmBase_Load(ByVal sender As Object, _
            ByVal e As System.EventArgs) Handles Me.Load

      Dim i As Integer

            For i = 0 To Me.Controls.Count - 1
                '  MsgBox(Me.Controls.Item(i).ToString)
                If Me.Controls.Item(i).GetType.Name = "Label" Or Me.Controls.Item(i).GetType.Name = "Button" Then
                    '  MsgBox(Me.Controls.Item(i).Text)
                    If My.Forms.fmMain.strLang = "TW" Then
                        Me.Controls.Item(i).Text = ChineseConverter.Convert(Me.Controls.Item(i).Text.ToString, ChineseConversionDirection.SimplifiedToTraditional)
                    ElseIf My.Forms.fmMain.strLang = "CN" Then
                        Me.Controls.Item(i).Text = ChineseConverter.Convert(Me.Controls.Item(i).Text.ToString, ChineseConversionDirection.TraditionalToSimplified)
                    End If
               ElseIf Me.Controls.Item(i).GetType.Name = "DataGridView" Then

     

                    Dim j As Integer

                    Dim DG As DataGridView = Me.Controls.Item(i)

                    Dim S As String; 
                    For j = 0 To DG.Columns.Count - 1

                       S=DG.Columns(j).HeaderText

                      If My.Forms.fmMain.strLang = "TW" Then

                      S=ChineseConverter.Convert(S,ChineseConversionDirection.SimplifiedToTraditional)

                      End If 

     

                      DG.Columns(j).HeaderText=S

                   Next



                    


                   

     

     End If


              
            Next

     

     

     

    2007年12月20日 上午 03:52

所有回覆

  •  

    程式碼區塊

    Imports Microsoft.International.Converters.TraditionalChineseToSimplifiedConverter
     
    Private Sub fmBase_Load(ByVal sender As Object, _
            ByVal e As System.EventArgs) Handles Me.Load

      Dim i As Integer

            For i = 0 To Me.Controls.Count - 1
                '  MsgBox(Me.Controls.Item(i).ToString)
                If Me.Controls.Item(i).GetType.Name = "Label" Or Me.Controls.Item(i).GetType.Name = "Button" Then
                    '  MsgBox(Me.Controls.Item(i).Text)
                    If My.Forms.fmMain.strLang = "TW" Then
                        Me.Controls.Item(i).Text = ChineseConverter.Convert(Me.Controls.Item(i).Text.ToString, ChineseConversionDirection.SimplifiedToTraditional)
                    ElseIf My.Forms.fmMain.strLang = "CN" Then
                        Me.Controls.Item(i).Text = ChineseConverter.Convert(Me.Controls.Item(i).Text.ToString, ChineseConversionDirection.TraditionalToSimplified)
                    End If
               ElseIf Me.Controls.Item(i).GetType.Name = "DataGridView" Then

     

                    Dim j As Integer

                    Dim DG As DataGridView = Me.Controls.Item(i)

                    Dim S As String; 
                    For j = 0 To DG.Columns.Count - 1

                       S=DG.Columns(j).HeaderText

                      If My.Forms.fmMain.strLang = "TW" Then

                      S=ChineseConverter.Convert(S,ChineseConversionDirection.SimplifiedToTraditional)

                      End If 

     

                      DG.Columns(j).HeaderText=S

                   Next



                    


                   

     

     End If


              
            Next

     

     

     

    2007年12月20日 上午 03:52
  • 感謝 CMF 的解答,解決了我的問題。
    2007年12月20日 上午 04:12