关于c#中dataGrid双击行头的行分割线位置提示异常的问题.

这个问题在.Net   Framework   RTM中的确存在。只要将DataGrid中某一行某一cell的 内容 完全删除,再双击这一行行头下面的分割线,就会出现这个错误。  
   
  错误的原因可以参考以下的stack   trace:  
   
        at   System.Globalization.CompareInfo.IndexOf(String   source,   String   value,   Int32   startIndex)  
        at   System.String.IndexOf(String   value,   Int32   startIndex)  
        at   System.Windows.Forms.DataGridTextBoxColumn.GetPreferredHeight(Graphics   g,   Object   value)  
        at   System.Windows.Forms.DataGrid.RowAutoResize(Int32   row)  
        at   System.Windows.Forms.DataGrid.OnMouseDown(MouseEventArgs   e)  
        at   System.Windows.Forms.Control.WmMouseDown(Message&   m,   MouseButtons   button,   Int32   clicks)  
        at   System.Windows.Forms.Control.WndProc(Message&   m)  
        at   System.Windows.Forms.ControlNativeWindow.OnMessage(Message&   m)  
        at   System.Windows.Forms.ControlNativeWindow.WndProc(Message&   m)  
        at   System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr   hWnd,   Int32   msg,   IntPtr   wparam,   IntPtr   lparam)  
        at   System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&   msg)  
        at   System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32   dwComponentID,   Int32   reason,   Int32   pvLoopData)  
        at   System.Windows.Forms.ThreadContext.RunMessageLoop(Int32   reason,   ApplicationContext   context)  
        at   System.Windows.Forms.Application.Run(Form   mainForm)  
        at   GeneralTest.Form1.Main()   in   c:/home/workspace/generaltest/form1.cs:line   253  
   
  从抛出的Exception的stack   trace中我们可以看到,当用户双击分割线时,DataGrid.RowAutoResize()会被调用,用来自动调整行的高度。而在DataGrid.RowAutoResize()内部会调用string.IndexOf("/r/n",0),当string的值为空时就会抛出 异常 。这就是为什么会有这个错误的原因。  
   
   
  解决这个错误的方法是继承DataGridTextBoxColumn类并重载GetPreferredHeight()函数,然后将新的MyDataGridTextBoxColumn类的实例添到DataGrid.TableStyles里面去。  
   
   
   
  Hogwarts   -   S(u)ddenly   dis@ppeared...    
  -    
  本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值