CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  VB.NET

这个问题我不会取名字了。。

楼主tttt0945()2004-09-03 22:38:21 在 .NET技术 / VB.NET 提问

是这样的,数据库里有个字段是asc2码,我可以通过在一个文本框输入汉字,然后导入数据库时要以asc2码存入,汉字和asc2转换到是不难,问题是我想让文本框绑定那个字段(但是text属性有没法绑定),这样可以比较方便的导航(因为在同一个界面我还要查看那个字段的内容)  
   
  不知大家有没有其他思路阿  
   
  问题点数:20、回复次数:4Top

1 楼AntingZ(夕惕若)回复于 2004-09-03 23:05:57 得分 0

Binding.Parse    
  Binding.FormatTop

2 楼AntingZ(夕惕若)回复于 2004-09-03 23:07:21 得分 20

ms-help://MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfSystemWindowsFormsBindingClassFormatTopic.htm  
   
  下面的示例创建一个   Binding,向   Parse   事件和   Format   事件添加   ConvertEventHandler   委托,并通过   DataBindings   属性向   TextBox   控件的   BindingsCollection   添加   Binding。添加到   Format   事件的   DecimalToCurrencyString   事件委托使用   ToString   方法将绑定值(Decimal   类型)格式化为货币。添加到   Parse   事件的   CurrencyStringToDecimal   事件委托将控件所显示的值回转为   Decimal   类型。  
  [Visual   Basic]    
  Private   Sub   DecimalToCurrencyString(sender   As   Object,   cevent   As   _  
  ConvertEventArgs)  
        '   The   method   converts   only   to   string   type.   Test   this   using   the   DesiredType.  
        If   Not   cevent.DesiredType   Is   GetType(String)   Then  
              Exit   Sub  
        End   If  
   
        '   Use   the   ToString   method   to   format   the   value   as   currency   ("c").  
        cevent.Value   =   CType(cevent.Value,   Decimal).ToString("c")  
  End   Sub  
   
  Private   Sub   CurrencyStringToDecimal(sender   As   Object,   cevent   As   _  
  ConvertEventArgs)  
        '   The   method   converts   back   to   decimal   type   only.  
        If   Not   cevent.DesiredType   Is   GetType(Decimal)   Then  
              Exit   Sub  
        End   If  
   
        '   Converts   the   string   back   to   decimal   using   the   static   ToDecimal   method.  
        cevent.Value   =   Decimal.Parse(cevent.Value.ToString,   _  
        NumberStyles.Currency,   nothing)  
  End   Sub  
   
  Private   Sub   BindControl  
        '   Creates   the   binding   first.   The   OrderAmount   is   a   Decimal   type.  
        Dim   b   As   Binding   =   New   Binding   _  
              ("Text",   ds,   "customers.custToOrders.OrderAmount")  
        '   Add   the   delegates   to   the   event  
        AddHandler   b.Format,   AddressOf   DecimalToCurrencyString  
        AddHandler   b.Parse,   AddressOf   CurrencyStringToDecimal  
        text1.DataBindings.Add(b)  
  End   Sub  
  Top

3 楼zhpsam109(JACKY.昊昊)回复于 2004-09-03 23:12:05 得分 0

学习!Top

4 楼tttt0945()回复于 2004-09-05 15:00:32 得分 0

多谢夕惕若!  
   
  我想问一下,这个format和parse方法的思路是不是这样的:就拿你那个示例来说,数据库的那个字段格式是decimal型的,现在要在textbox里显示其货币型的值,这是通过format方法来实现的,如果要导回数据库,这要通过parse方法使其转变为decimal型,是这样的吗?  
   
  Top

相关问题

  • 取个名字。
  • 频繁跨名字空间读取变量会不会影响速度?
  • 这个问题不大好取名字...内详...高手请进...
  • 给公司取个名字
  • 为小女取名字!
  • 取名字 (米老鼠)
  • 帮忙取个名字
  • 帮忙取个好名字
  • 给宝宝取个名字!
  • 帮小女孩取名字??

关键词

  • 字段
  • 数据库
  • cevent
  • decimal
  • currencystringtodecimal
  • desiredtype
  • decimaltocurrencystring
  • parse
  • 添加
  • 事件

得分解答快速导航

  • 帖主:tttt0945
  • AntingZ

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo