当前位置:编程学习 > C#/ASP.NET >>

DataGridview用button控件光标移

怎样写代码用button来控件DataGridview光标移动,上一行下一行,不要控件绑定.用纯代码写,希望各位高手帮忙,谢谢!!! --------------------编程问答-------------------- 把DataGridview控件对应行选中光标就可以实现上下移动吧,每一行都有一个属性表示该行是否被选中了[设置了DataGridview控件每次只能够单选一行记录] --------------------编程问答-------------------- 顶上去吧  关注! --------------------编程问答-------------------- //------------------上一条
        private void button3_Click(object sender, EventArgs e)
        {
            if (dataGridView1.Rows.Count > 0)
            {
                if (dataGridView1.CurrentCell.RowIndex != dataGridView1.Rows.Count - 1)
                {
                    int last = dataGridView1.SelectedRows[0].Index;
                    dataGridView1.CurrentCell = dataGridView1.Rows[last + 1].Cells[1];
                }
                else
                {
                    dataGridView1.CurrentCell = dataGridView1.Rows[0].Cells[1];
                }
            }
        }

//------------------下一条
        private void button11_Click(object sender, EventArgs e)
        {
            try
            {
                if (dataGridView1.CurrentCell.RowIndex != 0)
                {
                    int last = dataGridView1.SelectedRows[0].Index;
                    dataGridView1.CurrentCell = dataGridView1.Rows[last - 1].Cells[1];
                }
                else
                {
                    dataGridView1.CurrentCell = dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[1];
                }
            }
            catch { }
        } --------------------编程问答-------------------- 打错了 上一条跟下一条调换 --------------------编程问答-------------------- 顶一个!!!!! --------------------编程问答-------------------- 顶! --------------------编程问答-------------------- 顶一个、、、
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,