Hi to all!
I am having a 69 fields in datagrid, i can add data into it but as i have selected certain row, not all data displays on the corrsponding textbox. there are 5 fields didn't display "runtime error subscript out of range"...

here is the code:

Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
    lrn.Text = DataGrid1.Columns(0).Text
    schyr.Text = DataGrid1.Columns(1).Text
    ecomplete.Text = DataGrid1.Columns(2).Text
    nschool.Text = DataGrid1.Columns(3).Text
    ENG1.Text = DataGrid1.Columns(4).Text
    ENG2.Text = DataGrid1.Columns(5).Text
    ENG3.Text = DataGrid1.Columns(6).Text
    ENG4.Text = DataGrid1.Columns(7).Text
    ENG5Text = DataGrid1.Columns(8).Text
    ENG6.Text = DataGrid1.Columns(9).Text
    FIL1.Text = DataGrid1.Columns(10).Text
    FIL2.Text = DataGrid1.Columns(11).Text
    FIL3.Text = DataGrid1.Columns(12).Text
    FIL4.Text = DataGrid1.Columns(13).Text
    FIL5.Text = DataGrid1.Columns(14).Text


    FIL6.Text = DataGrid1.Columns(15).Text
    MATH1.Text = DataGrid1.Columns(16).Text
    MATH2.Text = DataGrid1.Columns(17).Text
    MATH3.Text = DataGrid1.Columns(18).Text
    MATH4.Text = DataGrid1.Columns(19).Text
    MATH5.Text = DataGrid1.Columns(20).Text
    MATH6.Text = DataGrid1.Columns(21).Text
    SCI1.Text = DataGrid1.Columns(22).Text
    SCI2.Text = DataGrid1.Columns(23).Text
    SCI3.Text = DataGrid1.Columns(24).Text
    SCI4.Text = DataGrid1.Columns(26).Text
    SCI5.Text = DataGrid1.Columns(26).Text
    SCI6.Text = DataGrid1.Columns(27).Text
    AP1.Text = DataGrid1.Columns(28).Text
    AP2.Text = DataGrid1.Columns(29).Text
    AP3.Text = DataGrid1.Columns(30).Text
    AP4.Text = DataGrid1.Columns(31).Text
    AP5.Text = DataGrid1.Columns(32).Text
    AP6.Text = DataGrid1.Columns(33).Text
    TLE1.Text = DataGrid1.Columns(35).Text
    TLE2.Text = DataGrid1.Columns(35).Text
    TLE3.Text = DataGrid1.Columns(36).Text
    TLE4.Text = DataGrid1.Columns(37).Text
    TLE5.Text = DataGrid1.Columns(38).Text
    TLE6.Text = DataGrid1.Columns(39).Text
    MUSIC1.Text = DataGrid1.Columns(40).Text
    MUSIC2.Text = DataGrid1.Columns(41).Text
    MUSIC3.Text = DataGrid1.Columns(42).Text
    MUSIC4.Text = DataGrid1.Columns(43).Text
    MUSIC5.Text = DataGrid1.Columns(44).Text
    MUSIC6.Text = DataGrid1.Columns(45).Text
    ARTS1.Text = DataGrid1.Columns(46).Text
    ARTS2.Text = DataGrid1.Columns(47).Text
    ARTS3.Text = DataGrid1.Columns(48).Text
    ARTS4.Text = DataGrid1.Columns(49).Text
    ARTS5.Text = DataGrid1.Columns(50).Text
    ARTS6.Text = DataGrid1.Columns(51).Text
    PE1.Text = DataGrid1.Columns(52).Text
    PE2.Text = DataGrid1.Columns(53).Text
    PE3.Text = DataGrid1.Columns(54).Text
    PE4.Text = DataGrid1.Columns(55).Text
    PE5.Text = DataGrid1.Columns(56).Text
    PE6.Text = DataGrid1.Columns(57).Text
    HEALTH1.Text = DataGrid1.Columns(58).Text
    health2.Text = DataGrid1.Columns(59).Text
    health3.Text = DataGrid1.Columns(60).Text
    health4.Text = DataGrid1.Columns(61).Text
    HEALTH5.Text = DataGrid1.Columns(62).Text
    HEALTH6.Text = DataGrid1.Columns(63).Text
    esp1.Text = DataGrid1.Columns(64).Text

below code are the value that won't display on the textbox

    txtesp.Text = DataGrid1.Columns(65).Text
    txtesp2.Text = DataGrid1.Columns(66).Text
    txtesp3.Text = DataGrid1.Columns(67).Text
    esp5.Text = DataGrid1.Columns(68).Text
    esp6.Text = DataGrid1.Columns(69).Text

Edited 1 Year Ago by Reverend Jim: Corrected code formatting

I notice you have one line

ENG5Text = DataGrid1.Columns(8).Text

that should probably be

ENG5.Text = DataGrid1.Columns(8).Text

You have

SCI4.Text = DataGrid1.Columns(26).Text
SCI5.Text = DataGrid1.Columns(26).Text

where you use column 26 twice. Should that be

SCI4.Text = DataGrid1.Columns(25).Text
SCI5.Text = DataGrid1.Columns(26).Text

Same thing for

TLE1.Text = DataGrid1.Columns(35).Text
TLE2.Text = DataGrid1.Columns(35).Text

As for the subscript out of range, the error is clear - you are trying to access a column that does not exist. What line is throwing the error and how many columns do you have in DataGridView1?

thank you for the correction. I been checking and corrected it already, I have 70 columns on my Datagridview1 and the line error throws in the following:

 esp2.Text = DataGrid1.Columns(65).Text
  esp3.Text = DataGrid1.Columns(66).Text
    esp4.Text = DataGrid1.Columns(67).Text
     esp6.Text = DataGrid1.Columns(69).Text

thank you onc again...

It occurred to me while trying a test that you may be accessing the data incorrectly. You want to access the values of the columns in a particular row. Perhaps what you want is something like

esp5.Text = DataGridView1.Rows(rownum).Cells(69).Value

In my version of vb.net (2010), DataGridView1.Columns returns a collection of all of the cells in a given column. As such, there is no Text property.

This article has been dead for over six months. Start a new discussion instead.