Avatar of SchoolTeacher54
SchoolTeacher54

asked on 

Writing a value to a datagrid

Hello,

I have an application that allows user to add a new record in a datagrid view for a list of users; small table.

I check to see if the user 'forgot' to add certain fields required by my program. If they forgot the field I write a default value for them. The situation is this:

1. I ADD a new record
2. The user is entered just fine while leaving out these two fields that I'm checking for.
3. This code errors out telling me that:
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll. Additional information: Index was out of range. Must be non-negative and less than the size of the collection.

I sure hope that you can help me!


Dim x
        x = Log_In_CredentialsDataGridView.SelectedRows(0).Cells(5).Value.ToString
        If x = "" Then Log_In_CredentialsDataGridView.SelectedRows(0).Cells(5).Value = 5

        Dim y
        y = Log_In_CredentialsDataGridView.SelectedRows(0).Cells(6).Value.ToString
        If y = "" Then Log_In_CredentialsDataGridView.SelectedRows(0).Cells(6).Value = 0
Visual Basic.NET.NET Programming

Avatar of undefined
Last Comment
David Johnson, CD
ASKER CERTIFIED SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo