Devendra Dwivedi
Devendra Dwivedi

Reputation:

InvalidArgument=Value of '3' is not valid for 'rowIndex'

This is my code It is working for if 1 terminal that is having 3 services but it is not working for more than 3 services when I do then I have got following error message:

InvalidArgument=Value of '3' is not valid for 'rowIndex'

I have so tired to find this problem but couldn't get any solutions. Anybody please help me.

MySqlCommand command = new MySqlCommand("VTerminalsLoad");//Procedure
MySqlDataAdapter terminalAdapter = this.Database.ExecuteCommand(command);
terminalAdapter.Fill(dataSet, "Terminals");

command = new MySqlCommand("VTServicesLoad");//Procedure
command.Parameters.Add(new MySqlParameter("pVesselID", 1));
MySqlDataAdapter serviceAdapter = this.Database.ExecuteCommand(command);//Return Adaptor
serviceAdapter.Fill(dataSet, "Services");

DataColumn[] parentColumns = { dataSet.Tables[0].Columns["SerialNo"], 
             dataSet.Tables[0].Columns["VesselID"], 
             dataSet.Tables[0].Columns["TerminalID"] };

DataColumn[] childColumns = { dataSet.Tables[1].Columns["SerialNo"], 
             dataSet.Tables[1].Columns["VesselID"], 
             dataSet.Tables[1].Columns["TerminalID"] };

DataRelation relationTS = new DataRelation("TerminalsServices", parentColumns, childColumns);
dataSet.Relations.Add(relationTS);

//Parent Table
ListTerminal.DataSource = dataSet;      //ListTerminal Parent datagridview  
ListTerminal.DataMember = "Terminals";

//Child Table
ListServices.DataSource = dataSet;// ListServices Child datagridview
ListServices.DataMember = "Terminals.TerminalsServices";

Upvotes: 0

Views: 2052

Answers (1)

LAM Yiu Pong Sam
LAM Yiu Pong Sam

Reputation: 21

See http://connect.microsoft.com/VisualStudio/feedback/details/116413/datagridview-exception-with-readonly-cells

This problem will be appear when: 1. DataGridView bind to a DataRelation 2. You try to set a DataGridViewCell in the first row to ReadOnly, before "BindingCompleted" (e.g.: On RowsAdded event of datagridview)

You can tackle this problem by delay the ReadOnly-Setting operation until BindingCompleted

Hope this can help you.

Upvotes: 2

Related Questions