chenJDataSet.pub_jiaoyuju.newrow()后,
执行以下语句会提示"pub_jiaoyujuBindingSource.Position"不存在.所以想在不是"插入","删除"状态下执行以下代码
            if (comboBox1.SelectedValue != null)
                comboBox1.SelectedValue = chenJDataSet.pub_jiaoyuju.Rows[pub_jiaoyujuBindingSource.Position]["parentid"];

解决方案 »

  1.   

    看看 chenJDataSet 是否榜定了
    看看 pub_jiaoyujuBindingSource.Position 是 -1 不如果是 -1
    证明 没榜定好,或没榜定上
    newrow() 后 add 回去没?还是把完整的代码贴出来吧
      

  2.   

    Dataset1.Tables[0].Rows[0].RowState而且 chenJDataSet.pub_jiaoyuju.Add(chenJDataSet.pub_jiaoyuju.newrow())
      

  3.   

    在vs2005环境中,chenJDataSet 已绑定,
    单击"bindingNavigatorAddNewItem"时执行pub_jiaoyujuBindingSource的AddNew()方法,在pub_jiaoyujuBindingSource_PositionChanged的事件中出错,主要是提示在"pub_jiaoyujuBindingSource.Position"没有任何行!如何解决? private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
            {
                this.pub_jiaoyujuBindingSource.AddNew();添加新行
            }       private void pub_jiaoyujuBindingSource_PositionChanged(object sender, EventArgs e)
            {            if (comboBox1.SelectedValue != null)
                    comboBox1.SelectedValue = chenJDataSet.pub_jiaoyuju.Rows[pub_jiaoyujuBindingSource.Position]["parentid"];
            }
      

  4.   

    //获取不同版本的DataRow
    using System;
    using System.IO;
    using System.Text;
    using System.Diagnostics;
    using System.Threading;
    using System.Collections;
    using System.Data;
    using System.Xml;
    using System.Management;
    using System.Net;
    namespace Zhzuo
    {
    class ZZConsole
    {
    [STAThread]
    static void Main(string[] args)
    {
    DataSet ds = new DataSet();
    CreatDataSetSchema(ds);
    InitData(ds);
    DataRow drdel = ds.Tables["Hosts"].Rows[0];
    drdel.Delete();
    Console.WriteLine(drdel.HasVersion(DataRowVersion.Default).ToString());
    foreach(DataRow dr in ds.Tables["Hosts"].GetChanges(DataRowState.Deleted).Rows)
    {
    //if(dr.HasVersion(DataRowVersion.Current))
    //{
    Console.WriteLine((string)dr["HId"]);
    Console.WriteLine(dr["IsLocal",DataRowVersion.Original].ToString());
    //}
    }
    Console.WriteLine("end");
    Console.ReadLine();
    }
    //初始化数据集结构
    private static void CreatDataSetSchema(DataSet ds)
    {
    DataTable dt = new DataTable("Hosts");
    DataColumn dc = new DataColumn("HId",typeof(String));
    dt.Columns.Add(dc);
    dc = new DataColumn("IsLocal",typeof(Boolean));
    dt.Columns.Add(dc);
    ds.Tables.Add(dt);
    }
    //加入数据
    private static void InitData(DataSet ds)
    {
    DataRow hostsRow = ds.Tables["Hosts"].NewRow();
    hostsRow["HId"] = "192.192.132.229";
    hostsRow["IsLocal"] = true;
    ds.Tables["Hosts"].Rows.Add(hostsRow); hostsRow = ds.Tables["Hosts"].NewRow();
    hostsRow["HId"] = "192.192.132.231";
    hostsRow["IsLocal"] = false;
    ds.Tables["Hosts"].Rows.Add(hostsRow); hostsRow = ds.Tables["Hosts"].NewRow();
    hostsRow["HId"] = "192.192.132.233";
    hostsRow["IsLocal"] = false;
    ds.Tables["Hosts"].Rows.Add(hostsRow);
    }
    }

    }