2013-07-21 115 views
0

此刻我有一個看起來像這樣的應用程序:加載/編輯並保存XML數據

它讀取上午XML文件中的數據到一個數據集,然後將數據源以適應這個數據網格

當某一行上的用戶點擊,註釋部分內的數據如下

enter image description here

當用戶點擊他們被帶到一個新形式的注按鈕上顯示一個文本框內,窗口2 ,在哪裏來自筆記文本框的電子數據被帶入新的文本框。我希望能夠做的就是能夠在形式2輸入新文本註釋文本框,然後當用戶點擊確定保存到數據網格

完全一樣:http://youtu.be/mdMjMObRcSk?t=28m41s

enter image description here

目前爲止,OK按鈕的代碼位於下方,並且出現以下錯誤,因爲我沒有在該窗體上寫入關於datagridview1的任何信息。

我想知道如何從文本框用戶輸入和「更新」的XML文件,以便在DataGrid與新的Notes

enter image description here

更新我不知道,如果這代碼將有助於但這是我怎麼也掛了datagridview1_cellcontentclick下面的文本框在Form1上,我想我需要重新使用新的窗體上的最後一行覆蓋數據,但我不知道

if (e.RowIndex >= 0) 
     { 
      DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex]; 
      //The data in the cells for the Notes Column turns into a string and is copied to the textbox below 
      textBox1.Text = row.Cells["somenotes"].Value.ToString(); 

謝謝任何幫助!

回答

1

我認爲你的問題與表單之間的聯繫有關(一個非常基本的問題)。你應該把窗口2的對話框,在Form1,告訴你它是這樣的:

//textBox1 is on your form1 
if(form2.ShowDialog(textBox1.Text) == DialogResult.OK){ 
    dataGridView1.Rows[dataGridView1.CurrentCellAddress.Y].Cells["somenotes"].Value = form2.Notes; 
    //perform your update to xml normally 
    //..... 
} 
//your Form2 
public class Form2 : Form { 
    public Form2(){ 
     InitializeComponent(); 
    } 
    public string Notes {get;set;} 
    public DialogResult ShowDialog(string initText){ 
     //suppose textBox is on your form2. 
     textBox.Text = initText; 
     return ShowDialog(); 
    } 
    private void OKButton_Click(object sender, EventArgs e){ 
     Notes = textBox.Text; 
     DialogResult = DialogResult.OK; 
    } 
    private void CancelButton_Click(object sender, EventArgs e){ 
     DialogResult = DialogResult.Cancel; 
    } 
} 
//form2 is defined in your Form1 class. 
+0

非常感謝了詳細的答覆我給它一個去後回來,如果我能得到它的工作:) – user2058186

+0

編輯形式2正如你所說的,現在只是嘗試form1 – user2058186

+0

我應該在哪裏放置你所建議的IF語句?謝謝 – user2058186