I am trying to use the CurrentRowChanging event to determine when the user changes a row in the grid. My grid is hierarchical with tabbed child views. I have a column that is hidden on the parent row for "comments". Instead, I have a text entry box else where in the UI that the user can type comments into for that row (parent row only). This is working fine when I only select parent rows. When I have expanded the child view and select a row there and then select a parent row, my code crashes. I presume that's because these are different tables in my data set. Is there an easy way from the event data to determine if I have two different tables/objects?
Code snippet here:
// This method will catch the CurrentRowChanging event in the Grid and will
// handle updating changing the comments in the text widget for each Job.
private void radGridView1_CurrentRowChanging(object sender, CurrentRowChangingEventArgs e)
{
// Check for error conditions
if ((e.CurrentRow == null) || (e.NewRow == null))
{
return;
}
if (e.NewRow.Cells["JobName"].Value == null)
return;
string newJobName = (string)e.NewRow.Cells["JobName"].Value;
string oldJobName = (string)e.CurrentRow.Cells["JobName"].Value;
// They changed rows within the job, but did not change jobs
if (newJobName == oldJobName)
{
return;
}
// save current text into old job
if (radTextBox1.Text == "")
{
e.CurrentRow.Cells["Comments"].Value = "";
}
else
{
e.CurrentRow.Cells["Comments"].Value = radTextBox1.Text;
}
// put new job comments into text widget
if (e.NewRow.Cells["Comments"].Value.ToString() == "")
{
radTextBox1.Text = "";
}
else
{
radTextBox1.Text = (string)e.NewRow.Cells["Comments"].Value; <<<< ------ crashes here
}
}
It crashes I'm sure because Comments is not a valid column for the child table.
Any suggestions would be appreciated.
John
Code snippet here:
// This method will catch the CurrentRowChanging event in the Grid and will
// handle updating changing the comments in the text widget for each Job.
private void radGridView1_CurrentRowChanging(object sender, CurrentRowChangingEventArgs e)
{
// Check for error conditions
if ((e.CurrentRow == null) || (e.NewRow == null))
{
return;
}
if (e.NewRow.Cells["JobName"].Value == null)
return;
string newJobName = (string)e.NewRow.Cells["JobName"].Value;
string oldJobName = (string)e.CurrentRow.Cells["JobName"].Value;
// They changed rows within the job, but did not change jobs
if (newJobName == oldJobName)
{
return;
}
// save current text into old job
if (radTextBox1.Text == "")
{
e.CurrentRow.Cells["Comments"].Value = "";
}
else
{
e.CurrentRow.Cells["Comments"].Value = radTextBox1.Text;
}
// put new job comments into text widget
if (e.NewRow.Cells["Comments"].Value.ToString() == "")
{
radTextBox1.Text = "";
}
else
{
radTextBox1.Text = (string)e.NewRow.Cells["Comments"].Value; <<<< ------ crashes here
}
}
It crashes I'm sure because Comments is not a valid column for the child table.
Any suggestions would be appreciated.
John