Question DatagridView won't show any data

mxnerd

New member
Joined
Nov 4, 2008
Messages
2
Programming Experience
Beginner
Hi, I'm new to VB.NET 2005 and tried to create an ASCII Table using DatagridView.

frmASCII is the name of the ASCII form

VB.NET:
Sub frmASCIILoad(ByVal sender As Object, ByVal e As EventArgs)

Dim i As Integer

For i = 0 To 255

    Dim r As New DataGridViewRow

    r.Cells("colHex").Value = Hex(i)
    r.Cells("colDecimal").Value = i.ToString
    r.Cells("colChar").Value = chr(i)

    'r.Cells(0).Value = Hex(i)
    'r.Cells(1).Value = i.ToString
    'r.Cells(2).Value = chr(i)
    
    Me.dgvASCII.Rows.Add(r)
Next

dgvASCII.Refresh    ' dgvASCII is the name of DataGridView, I tried to add this line and see if it make any difference, but it seems does nothing

End Sub

Using column name or column index won't show anything. what did i do wrong?

And why in design time, I can't change the names of columns of the DataGridView (colHex, colDecimal and colChar)? But it does show up in design time code view?
 
Got it working.

VB.NET:
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] frmASCII_Load([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Load[/SIZE]
 
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]  Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] i [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Short[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff] 
[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]  For[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] i = 0 [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] 255[/SIZE]
 
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]  Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] dr [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] DataGridViewRow[/SIZE]
[SIZE=2]    dr.CreateCells(dgvASCII)[/SIZE]
[SIZE=2]    dr.SetValues(Hex(i), i.ToString, Chr(i))[/SIZE]
[SIZE=2]    dgvASCII.Rows.Add(dr)[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]  Next[/COLOR][/SIZE]
[/COLOR][/SIZE]
[SIZE=2][/SIZE] 
[SIZE=2]  dgvASCII.AllowUserToAddRows = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE]
[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][/COLOR][/SIZE][/COLOR][/SIZE] 
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[/COLOR][/SIZE]
 
Back
Top