我想根据列头的名字获取不同的数据用于处理.我刚学,不太明白,请高手指教

解决方案 »

  1.   

    dataGridView1.Columns[0].HeaderText
    dataGridView1.Columns[0].Name
      

  2.   

    dataGridView1.Columns[0].HeaderCell.Value = "编号"; //第一列
    dataGridView1.Columns[1].HeaderCell.Value = "姓名"; //第二列
      

  3.   

    要想获得第一列的值   我这样写的
    int  sam= dataGridView1.RowCount;
    int V=0;
    for (int iV = 0; iV < sam - 1; iV++)
    {
       strVoltage[V] = dataGridView1[ 0,iV].Value.ToString();        
        V++;
    }
    但是调试时   为何出错    
      

  4.   

    strVoltage[V] = dataGridView1[ 0,iV].Value.ToString();    
    这句改成下面这句看看
    if(dataGridView1[ 0,iV].Value!=null)
      strVoltage[V] = dataGridView1[ 0,iV].Value.ToString();    
      

  5.   

    未处理 System.NullReferenceException
      Message="未将对象引用设置到对象的实例。"
      Source="电池检测软件"
      StackTrace:
           在 电池检测软件.frmlishishuju.trvlishi_NodeMouseDoubleClick(Object sender, TreeNodeMouseClickEventArgs e) 位置 E:\电池检测软件\电池检测软件\frmlishishuju.cs:行号 228
           在 System.Windows.Forms.TreeView.OnNodeMouseDoubleClick(TreeNodeMouseClickEventArgs e)
           在 System.Windows.Forms.TreeView.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)
           在 电池检测软件.Program.Main() 位置 E:\电池检测软件\电池检测软件\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()
      InnerException: 
      

  6.   

    你到底哪句出错,监控一下啊
    是不是strVoltage数组没有new吧
    如:strVoltage=new string[sam];
      

  7.   

    int sam= dataGridView1.RowCount;
    string[] strVoltage = new string[sam];
    int V=0;
    for (int iV = 0; iV < sam - 1; iV++)
    {
      if(dataGridView1[ 0,iV].Value!=null)
         strVoltage[V] = dataGridView1[ 0,iV].Value.ToString();   
      V++;
    }
      

  8.   

    就是没有new一下    谢谢了