this code gives me error of
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Dim i As Integer = 0
For Each r As DataRow In dt.Rows
DataGridView1.SelectedRows(i).Cells(i) = dt.Rows(i)("Emp_ID")
DataGridView1.SelectedRows(i).Cells(i) = dt.Rows(i)("Emp_Name")
DataGridView1.SelectedRows(i).Cells(i) = dt.Rows(i)("Day_Dat")
i = i + 1
Next
is there a problem clear here ? :(
Loading
sanjeev pandeyPosted Jan 17, 2013, 2:17 AM
maybe yout datatable has less rows data than selected rows of the datagridview.
Dinesh BhojePosted Jan 11, 2013, 5:03 AM
Santhosh Kumar JayaramanPosted Jan 9, 2013, 3:53 AM
http://www.c-sharpcorner.com/Forums/Thread/198310/handle-exceptions-and-debugging.aspx
Riddhi ValechaPosted Jan 9, 2013, 2:06 AM
Password - riddhi
Riddhi ValechaPosted Jan 9, 2013, 12:01 AM
Thanks in advance....
The attached zip is my code....
Santhosh Kumar JayaramanPosted Jan 8, 2013, 8:17 AM
Riddhi ValechaPosted Jan 8, 2013, 8:12 AM
Santosh: Please help me out in Silverlight issues dear.......
In my Silverlight Chat Application, when I debug the login page and redirect to next page, the control again comes back to login page and starts debugging...
I don't know what to do with it....
Please help...
Thanks in advance.,..
Santhosh Kumar JayaramanPosted Jan 8, 2013, 7:58 AM
ahmed fahdPosted Jan 8, 2013, 7:56 AM
Santhosh Kumar JayaramanPosted Jan 8, 2013, 7:14 AM
Check this sample grid example
Now using your code, if i have selected both the records, then first time
i=0
then,
DataGridView1.SelectedRows(0).Cells(0) = dt.Rows(0)("Emp_ID")
table will become
DataGridView1.SelectedRows(0).Cells(0) = dt.Rows(0)("Day_Dat")
So everytime its updating only EmpId column for each row.
So i meant use actual index., which is for empid column, index will be always 0, empname it will be 1, dept will always be 2.
So i asked you to rewrite like
Dim i As Integer = 0
For Each r As DataRow In dt.Rows
DataGridView1.SelectedRows(i).Cells(0) = dt.Rows(i)("Emp_ID")
DataGridView1.SelectedRows(i).Cells(1) = dt.Rows(i)("Emp_Name")
DataGridView1.SelectedRows(i).Cells(2) = dt.Rows(i)("Day_Dat")
i = i + 1
Next
ahmed fahdPosted Jan 8, 2013, 7:07 AM
Santhosh Kumar JayaramanPosted Jan 8, 2013, 6:03 AM
Because in your current code, you are updating same cell again and again with three columns.
First time you are updating cell 1 with Empid,
second line updating the same cell with empname
like this
ahmed fahdPosted Jan 8, 2013, 5:57 AM
but the rows not fixed
i have to take the 3 of 4 columns values from sql table
and give them to specified columns in my datagridview
so i tried to do loop, for the rows i retrieved and give them to the datagrid
Santhosh Kumar JayaramanPosted Jan 8, 2013, 5:47 AM
So now what happends if you have total of 2 rows and selected only one row, second time
inside the loop
it will become
DataGridView1.SelectedRows(1).Cells(1) = dt.Rows(1)("Emp_ID")
But there is only one selected row.
Similarly
If there are only 4 cells in a row and you have 10 rows, then again when you say cell(6), it will throw index out of range,
In general, index out of range will come if you dont have any element in that index.
If we get more requirements from you, we can exactly say which line error occurred