更新Winforms中的数据表值 [英] updating Datatable values in winforms

查看:58
本文介绍了更新Winforms中的数据表值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个数据表,其中有3行,3列(最小%,最大%,默认%)
值是字符串类型,值是2%,5%等等...
现在我想删除表中所有值的percent(%)...即列值应为2,5等...

请帮我解决同样的问题..

Hi,
I have a datatable which is having 3 rows ,3 columns (min %,max%,default%)
and the values are string type and values are like 2%,5% etc...
now i want to remove percentage(%) in all the values in the table...ie the column values should be 2,5 etc...

Please help me regarding the same..

推荐答案

对Colmns进行排序:
To Sort the Colmns:
dt.DefaultView.Sort="Column Name";


并在显示时添加%:


And to add % when you display:

Convert.ToString (row[col])+"%";


尝试一下!

Try this!

foreach (DataRow row in dt.Rows)
           {
             foreach (DataColumn col in dt.Columns){

             string h= Convert.ToString (row[col]);
              row[col]=  h.Replace ("%","");
            } 

           }

           dt.AcceptChanges();


这些列应为数字开头.无论在什么地方创建数据表(如果希望用户以这种方式在数字输入器中创建数字),都将转换为实际的数字值,并在显示值时应用适当的格式器.

如果使用的是DataGridView,则需要的钩子是DataGridView.CellValidating(用于输入)和DataGridViewColumn.DefaultCellStyle.FormatString(用于显示).
Those columns should be numeric to start with. Wherever you are creating the data table (and in the input validator if you expect the user to enter numbers that way), convert to the actual numeric value, and when you display values, apply the appropriate formatter.

If you''re using a DataGridView the hooks you want are DataGridView.CellValidating (for input) and DataGridViewColumn.DefaultCellStyle.FormatString (for display).


这篇关于更新Winforms中的数据表值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆