如题
我现在可以控制datagrid中的单元格只输入整数,如何输入浮点数???
ts.MappingName=dt1.TableName;
PropertyDescriptorCollection pdc = this.BindingContext[ds1,ff].GetItemProperties();
DataGridDigitsTextBoxColumn aColumnTextColumn2=new DataGridDigitsTextBoxColumn(pdc["hd"], "i", true);
.............
public class DataGridDigitsTextBoxColumn : DataGridTextBoxColumn
{
public DataGridDigitsTextBoxColumn(System.ComponentModel.PropertyDescriptor pd, string format, bool b) : base(pd, format, b)
{
this.TextBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(HandleKeyPress);
}
private void HandleKeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
//ignore if not digit or control key
if(!char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar))
e.Handled = true;
//ignore if more than 3 digits
if(this.TextBox.Text.Length >= 4 && !char.IsControl(e.KeyChar))
e.Handled = true;
}
.......
这里string format中的format除了"i"还有几种写法?
若为浮点数,private void HandleKeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)怎么写???
谢谢!!!
我现在可以控制datagrid中的单元格只输入整数,如何输入浮点数???
ts.MappingName=dt1.TableName;
PropertyDescriptorCollection pdc = this.BindingContext[ds1,ff].GetItemProperties();
DataGridDigitsTextBoxColumn aColumnTextColumn2=new DataGridDigitsTextBoxColumn(pdc["hd"], "i", true);
.............
public class DataGridDigitsTextBoxColumn : DataGridTextBoxColumn
{
public DataGridDigitsTextBoxColumn(System.ComponentModel.PropertyDescriptor pd, string format, bool b) : base(pd, format, b)
{
this.TextBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(HandleKeyPress);
}
private void HandleKeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
//ignore if not digit or control key
if(!char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar))
e.Handled = true;
//ignore if more than 3 digits
if(this.TextBox.Text.Length >= 4 && !char.IsControl(e.KeyChar))
e.Handled = true;
}
.......
这里string format中的format除了"i"还有几种写法?
若为浮点数,private void HandleKeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)怎么写???
谢谢!!!
http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q755q