小弟剛接觸c#及VB.net平台不久,請教前輩們,我在datatable中要設定字體顏色,如下程式碼中,當成交量(Volume)大於20顯示為紅色,成交量(Volume)小於20顯示為綠色,如以下程式碼中的'顯示字體為紅色這一段要如何寫,請各位大大幫我看一下,thanks!
Public Class Form1
Dim dtQuote As New DataTable
Private Sub QuoteTable()
If dtQuote.Columns.Count = 0 Then
dtQuote.Columns.Add("StockNo")
dtQuote.Columns.Add("Name")
dtQuote.Columns.Add("Volume", GetType(Integer))
End If
dtQuote.Rows.Clear()
End Sub
'載入表單
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
QuoteTable()
QuoteData()
End Sub
Private Sub QuoteData()
dtQuote.Rows.Add(2317, "鴻海", 50)
dtQuote.Rows.Add(2330, "台積電", 7)
dtQuote.Rows.Add(2412, "玉晶光", 28)
dtQuote.Rows.Add(2330, "聯發科", 16)
dtQuote.Rows.Add(2330, "國泰金", 31)
Dim i As Integer
For i = 0 To 4
If dtQuote.Rows(i)("volume") > 20 Then
'字體顯示為紅色
ElseIf dtQuote.Rows(i)("volume") < 20 Then
'字體顯示為綠色
End If
Next
End Sub
Private Sub ShowTable(ByVal dt As DataTable)
Dim fom As New Form
Dim dgv As New DataGridView
dgv.DataSource = dt
dgv.Dock = DockStyle.Fill
fom.Controls.Add(dgv)
fom.Show()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ShowTable(dtQuote)
End Sub
End Class
|