'非バインドの場合 Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.DataGridView1.ColumnCount = 1 Me.DataGridView1.RowCount = 4 Me.DataGridView1(0, 0).Value = 12L 'これらは Long 型(System.Int64 構造体) Me.DataGridView1(0, 1).Value = 12345L Me.DataGridView1(0, 2).Value = "12345" 'ここだけ、文字列型(System.String クラス)が混入している Me.DataGridView1(0, 3).Value = 123L ' 見た目では区別がつきませんが、 ' 実際のデータ型では Long / String の差異があることがわかります。 ' MsgBox(TypeName(Me.DataGridView1(0, 1).Value)) ' MsgBox(TypeName(Me.DataGridView1(0, 2).Value)) End Sub End Class
'DataTableをバインドした場合 Public Class Form1 Private ds As New DataSet() Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim tbl = ds.Tables.Add("tbl") tbl.Columns.Add("Num", GetType(Long)) tbl.Rows.Add(12L) tbl.Rows.Add(12345L) tbl.Rows.Add("12345") '本来は Long 型を渡すべきだが、あえて文字列側をセット tbl.Rows.Add(123L) ds.AcceptChanges() Me.DataGridView1.DataSource = ds Me.DataGridView1.DataMember = tbl.TableName 'この DataTable の Num 列は、予め Long 型である事を明示しているため、 '文字列が渡されても、自動的に Long 型に変換されて登録されています。 ' MsgBox(TypeName(tbl.Rows(2)(0))) ' MsgBox(TypeName(Me.DataGridView1(0, 2).Value)) End Sub End Class