G
Guest
I have a window application. In one of the form, a datagrid has a dataview
as its datasource. Initial filtering result would give the datavew 3 items.
When I double click on the datagrid to edit the selected lie item at which
case I would pop up a separate dialog box to do so, in the debugging code,
the dataview.count would return 0. I get a error message because I tried to
get values out of a dataview that holds 0 items. Does anyone know how do I
get around this problem?
I just want to pass the row that has been double clicked on the datagrid to
another dialog box for user to edit it and save the changes back to the
dataview/dataset.
Thanks, Alpha
private void dgMaintHistory_DoubleClick(object sender, System.EventArgs e)
{
int rowIndex = dgMaintHistory.CurrentRowIndex;
string filter = "ExtVID = " + curVid.ToString() + " and " + "ExtSchItemID
= " + lstSchItem.SelectedValue.ToString();
((DataView)dgMaintHistory.DataSource).RowFilter= filter;
// string miles = dgMaintHistory.CurrentRowIndex
// rowIndex = dsMaint.Tables["ServiceHistory"].
try
{
int count = dvServiceHistory.Count;
string datetest =
dvServiceHistory.Table.Rows[rowIndex]["ServiceDate"].ToString();
// .Table.Rows[rowIndex]["ServiceDate"].ToString;
int shid =
Convert.ToInt32(dvServiceHistory.Table.Rows[rowIndex]["SHistoryID"]);
datetest =
dvServiceHistory.Table.Rows[rowIndex]["ServiceDate"].ToString();
DataTable dtSrvHistory = new DataTable();
dtSrvHistory = dsMaint.Tables["ServiceHistory"];
datetest =
dsMaint.Tables["ServiceHistory"].Rows[rowIndex]["ServiceDate"].ToString();
// datetest =
dvServiceHistory.Table.Rows[rowIndex]["ServiceDate"].ToString();
// dsMaint.Tables["ServiceHistory"].
Form frmEditSrv = new EditServiceHistory(conMaint, dsMaint, shid);
frmEditSrv.ShowDialog();
dgMaintHistory.Refresh();
// ((DataView)lstSchItem.DataSource).RowFilter= strFilter;
frmEditSrv.Dispose();
}
catch(Exception ex)
{
MessageBox.Show("Error gettting the row to be modified." +
ex.ToString(), "Maintenance history error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
as its datasource. Initial filtering result would give the datavew 3 items.
When I double click on the datagrid to edit the selected lie item at which
case I would pop up a separate dialog box to do so, in the debugging code,
the dataview.count would return 0. I get a error message because I tried to
get values out of a dataview that holds 0 items. Does anyone know how do I
get around this problem?
I just want to pass the row that has been double clicked on the datagrid to
another dialog box for user to edit it and save the changes back to the
dataview/dataset.
Thanks, Alpha
private void dgMaintHistory_DoubleClick(object sender, System.EventArgs e)
{
int rowIndex = dgMaintHistory.CurrentRowIndex;
string filter = "ExtVID = " + curVid.ToString() + " and " + "ExtSchItemID
= " + lstSchItem.SelectedValue.ToString();
((DataView)dgMaintHistory.DataSource).RowFilter= filter;
// string miles = dgMaintHistory.CurrentRowIndex
// rowIndex = dsMaint.Tables["ServiceHistory"].
try
{
int count = dvServiceHistory.Count;
string datetest =
dvServiceHistory.Table.Rows[rowIndex]["ServiceDate"].ToString();
// .Table.Rows[rowIndex]["ServiceDate"].ToString;
int shid =
Convert.ToInt32(dvServiceHistory.Table.Rows[rowIndex]["SHistoryID"]);
datetest =
dvServiceHistory.Table.Rows[rowIndex]["ServiceDate"].ToString();
DataTable dtSrvHistory = new DataTable();
dtSrvHistory = dsMaint.Tables["ServiceHistory"];
datetest =
dsMaint.Tables["ServiceHistory"].Rows[rowIndex]["ServiceDate"].ToString();
// datetest =
dvServiceHistory.Table.Rows[rowIndex]["ServiceDate"].ToString();
// dsMaint.Tables["ServiceHistory"].
Form frmEditSrv = new EditServiceHistory(conMaint, dsMaint, shid);
frmEditSrv.ShowDialog();
dgMaintHistory.Refresh();
// ((DataView)lstSchItem.DataSource).RowFilter= strFilter;
frmEditSrv.Dispose();
}
catch(Exception ex)
{
MessageBox.Show("Error gettting the row to be modified." +
ex.ToString(), "Maintenance history error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}