首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

combobox设置默认值,SelectedIndexChanged事件中有有关问题

2014-01-19 
combobox设置默认值,SelectedIndexChanged事件中有问题在做数据库修改的时候遇到了问题在设置默认值的时候

combobox设置默认值,SelectedIndexChanged事件中有问题
在做数据库修改的时候遇到了问题
在设置默认值的时候,不管我是用comboBox_ID.SelectedIndex还是comboBox_ID.SelectedItem都不行。
不加comboBox_ID.SelectedIndex = int.Parse(Param.GetID()) - 1;的时候,SelectedIndexChanged没有问题,一加这句,我一改变comboBox_ID,就会出异常
这是界面:
combobox设置默认值,SelectedIndexChanged事件中有有关问题
加载的时候:


异常发生在txt_R1.Text = dr["R1"].ToString();
未处理 System.Data.RowNotInTableException
  Message=此行已从表中移除并且没有任何数据。BeginEdit() 将允许在此行中创建新数据
  Source=System.Data
  StackTrace:
       在 System.Data.DataRow.GetDefaultRecord()
       在 System.Data.DataRow.get_Item(String columnName)
       在 ASKME.ASKME_UPDATE_param.ShowParam() 位置 E:\Romtek\ASKME\ASKME\ASKME_UPDATE_param.cs:行号 95
       在 ASKME.ASKME_UPDATE_param.comboBox_ID_SelectedIndexChanged(Object sender, EventArgs e) 位置 E:\Romtek\ASKME\ASKME\ASKME_UPDATE_param.cs:行号 214
       在 System.Windows.Forms.ComboBox.OnSelectedIndexChanged(EventArgs e)


       在 System.Windows.Forms.ComboBox.WmReflectCommand(Message& m)
       在 System.Windows.Forms.ComboBox.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.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       在 System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam)
       在 System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, Message& m)
       在 System.Windows.Forms.Control.WmCommand(Message& m)
       在 System.Windows.Forms.Control.WndProc(Message& m)
       在 System.Windows.Forms.GroupBox.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.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       在 System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
       在 System.Windows.Forms.Control.DefWndProc(Message& m)
       在 System.Windows.Forms.Control.WmCommand(Message& m)
       在 System.Windows.Forms.Control.WndProc(Message& m)
       在 System.Windows.Forms.ComboBox.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(IntPtr 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)
       在 ASKME.Program.Main() 位置 E:\Romtek\ASKME\ASKME\Program.cs:行号 18
       在 System.AppDomain._nExecuteAssembly(RuntimeAssembly 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, Boolean ignoreSyncCtx)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       在 System.Threading.ThreadHelper.ThreadStart()
  InnerException: 


[解决办法]
for循环里面可以修改成这样


DataRow dr = ds.Tables["shape_param"].NewRow();
dr.ItemArray = (object[])ds.Tables["shape_param"].Rows[i - 1].ItemArray.Clone();
list.Add(i, dr);
listid.Add(i);

[解决办法]
把Param.GetID()的代码发来看下
[解决办法]
Param.GetID() 做了什么事情
[解决办法]
引用:
Quote: 引用:

把Param.GetID()的代码发来看下

我去 谢谢你 还真是那儿的问题。
也不知道我最开始写的时候怎么想的,ds放在外面这么写的

public static DataSet ds = new DataSet();

我靠 我把GetResult改了就好了。。。

        public static DataSet GetResult(string cmd, string grid)//查询返回DataSet
        {
            //ds.Clear();
            DataSet ds = new DataSet();
            ada = new MySqlDataAdapter(cmd, con);
            ada.Fill(ds, grid);
            return ds;
        }


啥意思,Clear()了?

热点排行