judithSampathwa -2 Posting Pro in Training

hi there,
how can i get the row index of the last row in the datagrid view in C#.

i have a add button that adds a row to the datagrid view if the three cells in the datagrid view curent row is not null.

when i try to add more rows the current cell row index is always 0. so the if loop runs. but w@ i wnat is to chek the privious row or the last row, whether it is null or not.

the code is below

if (tabControl1.SelectedIndex == 0)
            {
                int r1 = dgvAction.CurrentCell.RowIndex;
                if ((dgvAction.Rows[r1].Cells[0].Value != null) && (dgvAction.Rows[r1].Cells[1].Value != null) && (dgvAction.Rows[r1].Cells[2].Value != null))
                {
                    dgvAction.Rows.Add();
                    dgvAction.Rows[r1 + 1].Cells[1].Value = cbPW.Text;
                    //cbPW.TextChanged += new EventHandler(cbPW_TextChanged);
                    //cbPW.TextChanged += cbPW_TextChanged;
                }
                else
                    MessageBox.Show("enter action des, assign to, and due date in the previois row");
                r1 = 0;
            }

how can i solve this to get the the last row index of the datagrid view.

thanxxx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.