//把读到的配置文件放到_datatable中、、
            string file = Application.ExecutablePath;
            _config = ConfigurationManager.OpenExeConfiguration(file);
            _datatable = new DataTable();
            DataRow datarow;
            AppSettingsSection appSettings = (AppSettingsSection)_config.GetSection("appSettings");
            string[] keys = appSettings.Settings.AllKeys;
            _datatable.Columns.Add("配置项");
            _datatable.Columns.Add("参数值");
            for (int j = 0; j < keys.Length; j++)
            {
                datarow = _datatable.NewRow();
                string key = keys[j];
                string value = _config.AppSettings.Settings[key].Value;
                datarow["配置项"] = key;
                datarow["参数值"] = value;
                _datatable.Rows.Add(datarow);
            }//对修改的值进行保存。
            int rowIndex = e.RowHandle;
            GridColumn column = e.Column;
            int columnIndex = grvConfig.Columns.IndexOf(column);
            string value = grvConfig.GetFocusedRowCellValue("参数值").ToString();
            string chiKey = grvConfig.GetFocusedRowCellValue("配置项").ToString();
            string engKey = engAryline[rowIndex];
            for (int i = 0; i < keys.Length;i++ )
            {
                if (engKey == keys[i])
                {
                    _config.AppSettings.Settings[engKey].Value = value;
                }
            }
            _datatable.Rows[rowIndex][columnIndex] = value;

解决方案 »

  1.   

    如果是winform程序,
    那么它默认的配置文件就是 exe.config
      

  2.   


    我修改了参数,.exe.config也修改了,但是项目中的app.config没改变啊,下次运行它会不会又把exe.config的值还原成app.config的值你?
    app.config和exe.config什么联系呢?
    谢谢 给讲一讲
      

  3.   

    把代码编译以后,
    在bin\Debug或者bin\Release下面去看
    app.config是没有的,只有exe.config.
    修改config文件后记得保存,
    配置項是不会丢掉的
      

  4.   

    把代码编译以后,
    在bin\Debug或者bin\Release下面去看
    app.config是没有的,只有exe.config.
    修改config文件后记得保存,
    配置項是不会丢掉的
      

  5.   

    把代码编译以后,
    在bin\Debug或者bin\Release下面去看
    app.config是没有的,只有exe.config.
    修改config文件后记得保存,
    配置項是不会丢掉的
      

  6.   


    我的意思是为什么我项目中的app.config不跟着修改呢?
      

  7.   


    我的意思是为什么我项目中的app.config不跟着修改呢?
      

  8.   


    我的意思是为什么我项目中的app.config不跟着修改呢?
      

  9.   

    你生成的东西都在bin下,你调试的程序和你的配置文件都在bin下,修改也是在bin下,跟你项目里的config有什么关系,当然不会改你项目里的。
      

  10.   


    那app.config不修改,会不会把bin下的.exe.config给刷新掉?
    主要重新编译一下 不就把bin下的.exe.config给刷新掉了吗?
      

  11.   

    你可以右键你项目中的config文件,可以选择不复制,较新则复制或者始终复制。
      

  12.   

    在解决方案管理器那里,选中app.config 右键 选择始终复制文件,这样 您的app.config就会随着修改了
      

  13.   


    选择始终复制也不变啊?是不是我代码有问题?
    //获取当前运行程序的可执行文件的路径。
    string file = Application.ExecutablePath;
    //绑定打开配置文件
    Configuration _config = ConfigurationManager.OpenExeConfiguration(file);
    对_config 操作修改
    //之后就是保存,刷新
    _config.Save();
    ConfigurationManager.RefreshSection("configuration");
    帮忙看看?什么问题呢到底是?