编辑GridView时只能输入数字
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication4
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
// TODO: 这这这这这这这这这“行代将数据加到表testDataSet3.salary”中。您可以根据需
要移或移除它。这这这这这这
this.salaryTableAdapter.Fill(this.testDataSet3.salary);
// TODO: 这这这这这这这这这“行代将数据加到表testDataSet1.login”中。您可以根据需要
移或移除它。这这这这这这
this.loginTableAdapter.Fill(this.testDataSet1.login);
dataGridView1.Columns[0].ReadOnly = true;
dataGridView1.Columns[4].ReadOnly = true;
}
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
dataGridView1.Columns[0].ReadOnly = false;
int s1 = Convert.ToInt32(dataGridView1.CurrentRow.Cells[1].Value);
int s2 = Convert.ToInt32(dataGridView1.CurrentRow.Cells[2].Value);
int s3 = Convert.ToInt32(dataGridView1.CurrentRow.Cells[3].Value);
dataGridView1.CurrentRow.Cells[4].Value = s1 + s2 + s3;
int s4=s1 + s2 + s3;
SqlConnection conn = new SqlConnection(@"Server=(local);Integrated Security=True;"
+ "Database=Test");
conn.Open();
SqlCommand comm = new SqlCommand("update salary set 基本工这 ='" + s1 + "',这励
='" + s2 + "',全勤='"+s3+"',这这这工='"+s4+"'where 这工姓名='" +
dataGridView1.CurrentRow.Cells[0].ToString() + "' ", conn);
comm.ExecuteNonQuery();
//MessageBox.Show("修改成功:");
}
private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e)
{
//if (!char.IsDigit(e.KeyChar))
//{
// MessageBox.Show("sdfsdf");
// e.Handled = true;
//}
}
private void dataGridView1_CellValidating(object sender,
DataGridViewCellValidatingEventArgs e)
{
if (e.ColumnIndex == 1 || e.ColumnIndex == 2 ||e.ColumnIndex==3||e.ColumnIndex==4)
{
try
{
if (String.IsNullOrEmpty(e.FormattedValue.ToString()))
{
}
else
{
decimal val = decimal.Parse(e.FormattedValue.ToString());
}
}
catch (Exception ex)
{
dataGridView1.Rows[e.RowIndex].ErrorText = "必入数字这这这这这";
MessageBox.Show("这这 入数字");
e.Cancel = true;
}
}
}
}
}
本文档为【编辑GridView时只能输入数字】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。