0

我在这里有点困惑,我有一个数组bytes,我将其转换为 astring 然后拆分string并将拆分添加到 anArrayList 然后将其添加ArrayList到 aListView中。它以前可以工作,但现在不行,我不知道为什么。

//bytes to string.
string str = Encoding.Default.GetString(bytes);

// clear arraylist and listbox.
ItemDetails.Clear();
listBox1.Items.Clear();

// split the string and add the split into the arraylist.
ItemDetails.AddRange(str.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries));

// Add arraylist into listbox. It throws the generic error here:
listBox1.Items.AddRange(ItemDetails.ToArray());

异常详情:

System.Runtime.InteropServices.ExternalException was unhandled
  HResult=-2147467259
  Message=A generic error occurred in GDI+.
  Source=System.Drawing
  ErrorCode=-2147467259
  StackTrace:
       at System.Drawing.Graphics.MeasureString(String text, Font font, SizeF layoutArea, StringFormat stringFormat)
       at System.Drawing.Graphics.MeasureString(String text, Font font)
       at System.Windows.Forms.ListBox.UpdateMaxItemWidth(Object item, Boolean removing)
       at System.Windows.Forms.ListBox.ObjectCollection.AddInternal(Object item)
       at System.Windows.Forms.ListBox.ObjectCollection.AddRangeInternal(ICollection items)
       at System.Windows.Forms.ListBox.ObjectCollection.AddRange(Object[] items)
       at ItemTypeEditor.FrmMain.loadItems() in c:\Users\Nicolas\Desktop\ItemTypeEditor\ItemTypeEditor\FrmMain.cs:line 254
       at ItemTypeEditor.FrmMain.FrmMain_Load(Object sender, EventArgs e) in c:\Users\Nicolas\Desktop\ItemTypeEditor\ItemTypeEditor\FrmMain.cs:line 219
       at System.Windows.Forms.Form.OnLoad(EventArgs e)
       at System.Windows.Forms.Form.OnCreateControl()
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl()
       at System.Windows.Forms.Control.WmShowWindow(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.ContainerControl.WndProc(Message& m)
       at System.Windows.Forms.Form.WmShowWindow(Message& m)
       at System.Windows.Forms.Form.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

我知道这里没有很多信息,所以如果您需要任何其他详细信息,请告诉我。

4

1 回答 1

2

尝试重新创建控制。可能 Initialize() 中的设计器代码已损坏。看起来列表框无法更新项目的宽度,因为测量字符串失败。

您能否从 Initialize 中发布描述 listBox1 的代码?

于 2013-08-01T08:48:18.497 回答