Results 1 to 2 of 2

Thread: Argument out of range

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2011
    Posts
    119

    Argument out of range

    Hi, Greetings,
    I have this problem just new to this.
    thanks

    Dim NewDataRow As New DataGridViewRow
    NewDataRow.Cells(1).Value = EMSECodeTxtBox.Text
    NewDataRow.Cells(2).Value = TeacherNameTxtBox.Text
    NewDataRow.Cells(4).Value = FatherNameTxtBox.Text
    NewDataRow.Cells(5).Value = DateofTxtBox.Text
    NewDataRow.Cells(6).Value = AgeTxtbox.Text
    NewDataRow.Cells(7).Value = HomeTecherForTxtBox.Text
    NewDataRow.Cells(8).Value = QualificationTxtBox.Text
    NewDataRow.Cells(9).Value = YearsOfPassingTxtBox.Text
    NewDataRow.Cells(10).Value = UniversityTxtBox.Text
    NewDataRow.Cells(11).Value = JoiningDateTxtBox.Text
    NewDataRow.Cells(12).Value = MobileNumberTxtBox.Text
    NewDataRow.Cells(13).Value = CityTxtBox.Text
    NewDataRow.Cells(14).Value = EmailTxtBox.Text
    NewDataRow.Cells(15).Value = AddressTxtBox.Text
    NewDataRow.Cells(16).Value = SalaryTxtBox.Text
    Attached Images Attached Images  

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,754

    Re: Argument out of range

    This typically means that you're trying to access an item in a collection by its index where the item does not exist. In your particular instance, you've never added any columns to the DataGridViewRow so any index in the Cell collection does not exist.

    To fix the issue, use the CreateCells method to populate the Cell collection and to also pass your values:
    Code:
    NewDataRow.CreateCells(DataGridView1, New Object() {EMSECodeTxtBox.Text, TeacherNameTxtBox.Text, FatherNameTxtBox.Text, etc...})
    Also, for what its worth collections in .NET have a 0 based index which means that Collection(0) is the first item, not Collection(1).
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width