如何默认选择gridview第一行 [英] how Select defaultly the gridview first Row

查看:599
本文介绍了如何默认选择gridview第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1。我在点击事件上有一个按钮,它显示了一个行数的数据视图。



2.我想默认选择第一行或第二行,这样我就可以导航datagrid

通过向上和向下键。



3.在Enter键事件我想要一些选定的行详细信息







1. I have a button on click event it show a datagridview which had number of rows

2. i Want to select the first row or second row defaultly so i can navigate the datagrid
through with up and down key.

3. The on Enter key event i want to some selected row details



public frmRoomAvailability(Transactions.frmCheckINNEW objcheckIn)
       {
           objCheckIn = objcheckIn;
           InitializeComponent();
           getdgv();

       }

 public void getdgv()
        {
            DataSet ds = new DataSet();
            ds = DB.ExecuteQuery_SP("SelectAllVacantRoom");
            try
            {
                if (ds.Tables.Count > 0)
                {
                    dgvsvail.DataSource = ds.Tables[0];
                   
                    Generalclass.ROOMID = Convert.ToInt32(ds.Tables[0].Rows[0]["RoomID"].ToString());
                }
            }
            catch (Exception ex) { }
        }

推荐答案

最简单的方法是:

The simplest way is:
dgv.Rows[index].Selected = True;



其中第一行的 index 等于 0 (零)。

注意:必须至少有一行,否则会出错!


where index for first row is equal to 0 (zero).
Note: there must be at least one row, otherwise the error occurs!


这篇关于如何默认选择gridview第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆