如何从datagridview编辑并保存新的更改 [英] How to edit from the datagridview and save new changes

查看:508
本文介绍了如何从datagridview编辑并保存新的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个资源文件,我读取数据并将其加载到网格视图。现在我希望用户能够从网格编辑并单击保存按钮,将其保存为resx的新文件?我怎么做?这是读取文件的代码。



 oDataSet =  new 数据集(); 
// 现在正在读取所选路径中的文件
XmlReadMode omode = oDataSet.ReadXml(PathSelection);

for int i = 0 ; i < oDataSet.Tables [ 2 ]。Rows.Count; i ++ )
{
string comment = oDataSet.Tables [ data]。行[i] [ 2 ]。ToString();
string font = Between(comment, [字体] [/ Font]);
string datestamp = Between(comment, [DateStamp] [/ DateStamp]);
string commentVal = Between(comment, [Comment] [/ Comment]);

string [] row = new string []
{
oDataSet.Tables [ data].Rows[i][ 0 ]。ToString(),
oDataSet.Tables [ data]。行[i] [ 1 ]。ToString(),
字体,
datestamp,
commentVal
};

Gridview_Input.Rows.Add(row);





代码,我试过但这不起作用。任何帮助请



  foreach (DataGridViewRow _gd  in  Gridview_Input.Rows)
{
DataRow _row = oDataSet.Tables [ 数据] NEWROW();
_row [ 0 ] = oDataSet.Tables [ data]。行[ 0 ] [ 0 ]。ToString();
if (_gd.Cells [ 1 ]。Value.ToString()!= null
_row [ 1 ] = _gd.Cells [ 1 ] Value.ToString();

if (_gd.Cells [ 2 ]。Value.ToString() != null
_row [ 2 ] = _gd.Cells [ 2 ] Value.ToString();

if (_gd.Cells [ 3 ]。Value.ToString() != null
_row [ 3 ] = _gd.Cells [ 3 ] Value.ToString();

if (_gd.Cells [ 4 ]。Value.ToString() != null
_row [ 4 ] = _gd.Cells [ 4 ] Value.ToString();

oDataSet.Tables [ data]。Rows.Add(_row );
Gridview_Input.Rows.Add(_row);
}

解决方案

试试这个



http://www.worldbestlearningcenter.com/index_files/csharp-entity-framework -datagridview-add-delete-edit-rows.htm [ ^ ]



http://stackoverflow.com/questions/15424768/datagridview-cell-edit-and-save-functionality-in-windows-表格 [ ^ ]

I have a resource file which i read the data and load it to the grid-view. now i want the user to be able to edit from the grid and click save button which will save it as a new file of resx? how do i do that? this is the code for reading the file.

oDataSet = new DataSet();
//now am reading the files from the path that is selected
XmlReadMode omode = oDataSet.ReadXml(PathSelection);

for (int i = 0; i < oDataSet.Tables[2].Rows.Count; i++)
{
    string comment = oDataSet.Tables["data"].Rows[i][2].ToString();
    string font = Between(comment, "[Font]","[/Font]");
    string datestamp = Between(comment, "[DateStamp]", "[/DateStamp]");
    string commentVal = Between(comment, "[Comment]", "[/Comment]");

    string[] row = new string[]
    {
        oDataSet.Tables["data"].Rows[i][0].ToString(),
        oDataSet.Tables["data"].Rows[i][1].ToString(),
        font,
        datestamp,
        commentVal
    };

    Gridview_Input.Rows.Add(row);



code that i tried but this didn't work. any help please

foreach (DataGridViewRow _gd in Gridview_Input.Rows)
               {
                   DataRow _row = oDataSet.Tables["data"].NewRow();
                   _row[0] = oDataSet.Tables["data"].Rows[0][0].ToString();
                   if (_gd.Cells[1].Value.ToString() != null)
                       _row[1] = _gd.Cells[1].Value.ToString();

                   if (_gd.Cells[2].Value.ToString() != null)
                       _row[2] = _gd.Cells[2].Value.ToString();

                   if (_gd.Cells[3].Value.ToString() != null)
                       _row[3] = _gd.Cells[3].Value.ToString();

                   if (_gd.Cells[4].Value.ToString() != null)
                       _row[4] = _gd.Cells[4].Value.ToString();

                   oDataSet.Tables["data"].Rows.Add(_row);
                   Gridview_Input.Rows.Add(_row);
               }

解决方案

try this

http://www.worldbestlearningcenter.com/index_files/csharp-entity-framework-datagridview-add-delete-edit-rows.htm[^]

http://stackoverflow.com/questions/15424768/datagridview-cell-edit-and-save-functionality-in-windows-forms[^]


这篇关于如何从datagridview编辑并保存新的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆