Reputation: 287
at the moment I have an application that looks like this:
It reads data from am XML file into a dataset, and then sets the datasource to fit into this datagrid
When the user clicks on a row, the data within the Notes section are displayed within a textbox below
When the user clicks the Notes button they are brought to a new form, form2, where the data from the notes textbox is brought across into a new textbox. What I want to be able to do is be able to enter new text into the Notes textbox on form 2 and then when the user clicks ok it saves to the datagrid
exactly like this: http://youtu.be/mdMjMObRcSk?t=28m41s
The code I have at the moment for the OK button so far is below, and I get the following error because I haven't wrote anything about datagridview1 on that form.
I'd like to know how to get user input from the textbox and 'update' the XML file so that the datagrid is updated with new Notes
I'm not sure if this code will help but this is how I have linked the datagridview1_cellcontentclick to the textbox below on form1, I think I need to reuse the last line on the new form to overwrite the data but i'm not sure
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();
thank for any help!
Upvotes: 0
Views: 1425
Reputation: 63357
I think your problem is related to contacting between forms (a very basic problem). You should treat form2 as a dialog, in form1, you show it like this:
//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.
Upvotes: 1