'Exception thrown: System.ArgumentOutOfRangeException
I am following a Youtube video tutorial, so it should be straightforward with everything working since someone already worked out the errors....except since I am here you know it's not the case!
Here I am trying to add a feature that when you click on a cell box in a data grid RoomsDGV (in a form) it then brings the relevant data into a text box e.g RnameTb
The problem I am having is that these lines are bringing up an error when I click onto the cell:
System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection. Arg_ParamName_Name'
I have no idea if this makes sense or if I have included enough information. I am very new to coding, C# and SQL... If anyone can shed some light on what is happening I would be very grateful!
int key = 0;
private void RoomsDGV_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
RNameTb.Text = RoomsDGV.SelectedRows[0].Cells[1].Value.ToString();
RTypeCb.Text = RoomsDGV.SelectedRows[0].Cells[2].Value.ToString();
StatusCb.Text = RoomsDGV.SelectedRows[0].Cells[3].Value.ToString();
if(RNameTb.Text == "")
{
key = 0;
}
else
{
key = Convert.ToInt32(RNameTb.Text = RoomsDGV.SelectedRows[0].Cells[0].Value.ToString());
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
