这个问题在.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)。
错误的原因可以参考以下的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)。