WInform 常用属性

    技术2022-05-19  22

    1.获取dataGridView选择行的控件的值: dataGridView.SelectedCells[0].EditedFormattedValue.ToString()  获取选择行某一列的值:dataGridView.CurrentRow.Cells[1].Value  或者:dataGridView.CurrentRow.Cells["列名"].Value   (列名:是Name不是Title)

    2.判断dataGridView内部checkBox的选中事件: bool check = dataGridView.Rows[0].Cells[1].Selected;

    3.解决dataGridView列的顺序和自己排列的顺序不一致: this.dataGridView.AutoGenerateColumns = false;(在数据绑定前加载该属性)

    4.判断dataGridView单击事件触发的是该行那一列的事件: dataGridView_CellClick或者dataGridView_CellContentClick 的事件 e.ColumnIndex == 0

    5.弹出窗口的为位置设定:startposion的属性:centerscreen

    6.获取DataTable第一行,第一列的值:DataTable..Rows[0].ItemArray[0].

    7.获取当前登录用户的用户名: Environment.UserName

    8.去掉dataGridView最后一行留白:this.dataGridView1.AllowUserToAddRows = false;

    9.SQL获取今天的所有数据:select   *   from   article   where   AddTime> =convert(char(10),   getdate(),   120) and   AddTime <convert(char(10),   getdate()+1,   120)      或者  where   convert(varchar(20),AddTime,120)=convert(varchar(20),getdate(),120)

    10.获取查询语句前面的自动编号: ROW_NUMBER()OVER(ORDER BY Batch_No)  前面有个排序规则

    11.当点击savefiledialog保存按钮的时候才执行 :   if (sfdFX.ShowDialog() == DialogResult.OK)  //如果点的是确定就得到文件路径

    12.解决DataGridView 的下面出现被覆盖一部分的情况: Location 的 y=0, x=0

    13:         DataTable roleTable  = ParameterSetter.Get_RoleInfo().Tables[0];  (设置下拉菜单的TEXT和VALUE)            cbxRoleName.DataSource = roleTable;            cbxRoleName.DisplayMember = "RoleName";            cbxRoleName.ValueMember = "RoleID";

    14.          //string sql = "select * from table where 1=1";            //if(str[0].Length>0)            //    sql += " and field1 = @field1";            //if(str[1].Length>0)            //    sql += " and field2 = @field2";            //List<SqlParameter> parameters = new List<SqlParameter>();            //if(str[0].Length>0)            //    parameters.Add(new SqlParameter("@field1",str[0]));            //if(str[1].Length>0)            //    parameters.Add(new SqlParameter("@field2",str[1]));

    15.当前窗口禁止拖放:this.FormBorderStyle = FormBorderStyle.FixedSingle;

    16.任务栏不显示当前窗口:ShowInTaskbar=false;

    17.窗体不显示最大化,最小化的按钮:FormBorderStyle=FixedDialog;

    18.禁用窗体最大化最小化:MaximizeBox=false;MinimizeBox=false;

    19. 验证输入必须为数字和字母的组合:if (!Regex.Match(iSINCode, @"(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{2,})$").Success)                {                    MessageBox.Show("ISINCode,Format is not correct !", "Message");                    return;                }

    20. 判断验证时间为输入的数据:   WHERE datediff(dd,FXBookingDate,@DateTime)=0   (dd为验证天,MM验证月份,yyyy验证年份)

     


    最新回复(0)