参考如下代码
using System.Runtime.InteropServices;[DllImport("User32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("User32.dll")]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
public const int GWL_STYLE = -16;
public const int ES_NUMBER = 0x2000;private void dataGridView1_EditingControlShowing_1(object sender,
DataGridViewEditingControlShowingEventArgs e)
{
if (e.Control is DataGridViewTextBoxEditingControl)
{
if (((DataGridView)sender).CurrentCell.ColumnIndex == 0) // 第一列
{
SetWindowLong(e.Control.Handle, GWL_STYLE,
GetWindowLong(textBox1.Handle, GWL_STYLE) | ES_NUMBER);
}
else
{
SetWindowLong(e.Control.Handle, GWL_STYLE,
GetWindowLong(textBox1.Handle, GWL_STYLE) & ~ES_NUMBER);
}
}
}
using System.Runtime.InteropServices;[DllImport("User32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("User32.dll")]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
public const int GWL_STYLE = -16;
public const int ES_NUMBER = 0x2000;private void dataGridView1_EditingControlShowing_1(object sender,
DataGridViewEditingControlShowingEventArgs e)
{
if (e.Control is DataGridViewTextBoxEditingControl)
{
if (((DataGridView)sender).CurrentCell.ColumnIndex == 0) // 第一列
{
SetWindowLong(e.Control.Handle, GWL_STYLE,
GetWindowLong(textBox1.Handle, GWL_STYLE) | ES_NUMBER);
}
else
{
SetWindowLong(e.Control.Handle, GWL_STYLE,
GetWindowLong(textBox1.Handle, GWL_STYLE) & ~ES_NUMBER);
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货