datagridview相关

时间:2020-06-19 10:33:30   收藏:0   阅读:49

一、控制cell输入格式(整数为例)

 

        //private void dataGridView5_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        //{
        //    if (dataGridView1.Rows[e.RowIndex].IsNewRow) return;
        //    int dci;
        //    if (e.ColumnIndex == 4 || e.ColumnIndex == 6 || e.ColumnIndex == 7)
        //    {
        //        if (e.FormattedValue != null && e.FormattedValue.ToString().Length > 0)
        //        {
        //            if (!int.TryParse(e.FormattedValue.ToString(), out dci) || dci < 0)
        //            {
        //                e.Cancel = true;
        //                MessageBox.Show("请输入整数", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        //            }
        //        }
        //    }
        //}

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!