DataGridView数值列排序问题[非DataSource绑定,有经验的请进]■■■■■■■■■

ssrwf 2007-07-03 10:15:51
DataGridView(dgvInfo):
种类  价格
汽车  14
火车
飞机 100

数据库中(dataTable):
KIND  PRICE
0   14
1 null
2 100

foreach (DataRow row in dataTable.Rows)
{
object[] dgvRow ={
GetNameByCode(row["KIND"]),""), //code转name
row["AVR_PRICE"]};

dgvInfo.Rows.Add(dgvRow);
}

我点击价格排序的时候出现Exception.
可能是null比较时候出的问题
但是用DataSource绑定不会有这种问题,高手的帮个忙.
...全文
236 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ssrwwy 2007-07-03
  • 打赏
  • 举报
回复
顶......................
ssrwwy 2007-07-03
  • 打赏
  • 举报
回复
顶...............
ssrwwy 2007-07-03
  • 打赏
  • 举报
回复
顶......
ssrwf 2007-07-03
  • 打赏
  • 举报
回复
オブジェクトは Int32 型でなければなりません。

stack:
場所 System.Int32.CompareTo(Object value)
場所 System.Collections.Comparer.Compare(Object a, Object b)
場所 System.Windows.Forms.DataGridViewRowCollection.RowComparer.CompareObjects(Object value1, Object value2, Int32 rowIndex1, Int32 rowIndex2)
場所 System.Windows.Forms.DataGridViewRowCollection.RowArrayList.CustomQuickSort(Int32 left, Int32 right)
場所 System.Windows.Forms.DataGridViewRowCollection.Sort(IComparer customComparer, Boolean ascending)
場所 System.Windows.Forms.DataGridView.SortInternal(IComparer comparer, DataGridViewColumn dataGridViewColumn, ListSortDirection direction)
場所 System.Windows.Forms.DataGridView.Sort(DataGridViewColumn dataGridViewColumn, ListSortDirection direction)
場所 System.Windows.Forms.DataGridView.OnColumnHeaderMouseClick(DataGridViewCellMouseEventArgs e)
場所 System.Windows.Forms.DataGridView.OnMouseClick(MouseEventArgs e)
場所 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
場所 System.Windows.Forms.Control.WndProc(Message& m)
場所 System.Windows.Forms.DataGridView.WndProc(Message& m)
場所 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
場所 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
場所 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
場所 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
場所 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
場所 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
場所 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
場所 System.Windows.Forms.Application.Run(Form mainForm)
場所 DBView.Program.Main() 場所 E:\WebGrab\DBView\Program.cs:行 18
場所 System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
場所 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
場所 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
場所 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
場所 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
場所 System.Threading.ThreadHelper.ThreadStart()

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧