2017-07-25 89 views
0
Try 
     Dgrd.Rows.Clear() 
     ItDataset.Clear() 
     Flt = "SELECT * FROM TransView WHERE TRACom = N'" & Trim$(T10ID.Text) & "'" Order By TRAID" 
     ItDataset = GeneralDataManager.InquireData(ItDataset, Flt, "TransView") 
     If Me.BindingContext(ItDataset, "TransView").Count > 0 Then 
      For I As Integer = 0 To ItDataset.Tables("TransView").Rows.Count - 1 
       Dim row As String() = 
         {ItDataset.Tables("TransView").Rows(I).Item("TRAID"), 
         ItDataset.Tables("TransView").Rows(I).Item("Sender"), 
         ItDataset.Tables("TransView").Rows(I).Item("Recever"), 
         ItDataset.Tables("TransView").Rows(I).Item("TRAValue"), 
         ItDataset.Tables("TransView").Rows(I).Item("CurrnceyName"), 
         ItDataset.Tables("TransView").Rows(I).Item("TRADT"), 
         ItDataset.Tables("TransView").Rows(I).Item("OFCEName")} 
        Dgrd.Rows.Add(row) 
       End If 
      Next 
      TXTGREDTotal.Text = Dgrd.RowCount - 1 
     End If 
    Catch ex As Exception 
     Exit Sub 
    End Try 

我有布爾AS(ItDataset.Tables( 「TransView」)。行(I).Item( 「TRAYesORNo」)) 我怎麼可以把這個布爾到字符串,將它添加到我的DataGridView?將布爾轉換爲字符串在Datagridview中?

回答

0

您不必將其轉換爲String。只需將該來源列綁定到DataGridViewTextBoxColumn而不是默認的DataGridViewCheckBoxColumn。爲此,請在設計器的網格中添加一個文本框列,並將其DataPropertyName設置爲源列的名稱。現在,當您綁定時不會創建新列,您將看到文本「True」或「False」而不是複選框。

+0

謝謝您的回答..但我想寫文字顯示在我的DataGridView。 – Aladein

+0

哎,如果我知道的話。除了我知道這一點,這就是爲什麼我告訴你如何去做。你有沒有看到我說文字會顯示的部分?是否說我使用TEXT box列而不是文本會成爲結果? – jmcilhinney

+0

你是說,沒有真正地說,你不想將'DataTable'綁定到網格?如果是這樣,爲什麼不呢?如果沒有好的理由不約束,那麼明智的事情就是束縛。當然,你可以做你想做的事情,但是你爲什麼不以最明智的方式去做? – jmcilhinney

0

我找到了答案:

Dim TRAYesORNo As String = "" 
    Try 
    Dgrd.Rows.Clear() 
    ItDataset.Clear() 
    Flt = "SELECT * FROM TransView WHERE TRACom = N'" & Trim$(T10ID.Text) & "'" Order By TRAID" 
    ItDataset = GeneralDataManager.InquireData(ItDataset, Flt, "TransView") 
    If Me.BindingContext(ItDataset, "TransView").Count > 0 Then 
     For I As Integer = 0 To ItDataset.Tables("TransView").Rows.Count - 1 
     If ItDataset.Tables("TransView").Rows(I).Item("TRAYesORNo") = False Then 
         TRAYesORNo = "YES" 
        Else 
         TRAYesORNo = "NO" 
        End If 
      Dim row As String() = 
        {ItDataset.Tables("TransView").Rows(I).Item("TRAID"), 
        ItDataset.Tables("TransView").Rows(I).Item("Sender"), 
        ItDataset.Tables("TransView").Rows(I).Item("Recever"), 
        ItDataset.Tables("TransView").Rows(I).Item("TRAValue"), 
        ItDataset.Tables("TransView").Rows(I).Item("CurrnceyName"), 
        ItDataset.Tables("TransView").Rows(I).Item("TRADT"), 
        ItDataset.Tables("TransView").Rows(I).Item("OFCEName")} 
       Dgrd.Rows.Add(row) 
      End If 
     Next 
     TXTGREDTotal.Text = Dgrd.RowCount - 1 
    End If 
Catch ex As Exception 
    Exit Sub 
End Try