i'm trying to get the last row but the problem is....see my code
Int32 index=dataGridveiw1.Rows.Count; // this is count start 1,2,3,4,5,6
sum3=txt_lotweight.Text-txt_balanceweight.Text;
sum4=datagridview1.Rows[index].Cells["rollweight"].Value-sum3;
how to minus gridview last row value to sum3 in this code error will come rows index not found because rows count start from 1 and when i subtract rows value to sum3 its start from 0
so how to get last row of gridview
You can get the selected row indexes by using the selectedRowsIndexes property in Grid.
You are not getting last row index, but count that is higher by 1 than last index! That is because array indexing in C# starts from 0.
Int32 index = dataGridveiw1.Rows.Count - 1; // this is count start 1,2,3,4,5,6
this code will work. But I have doubts about your sum3
- if your TextBox
contains integers you should cast it to int
before subtracting, and Value
in sum4 is object so casting is required as well.
Index are basically starts from 0 so if you are using the row count then you have to use it like this to get the last index.
Int32 index=dataGridveiw1.Rows.Count - 1 ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With