我想從下面的代碼訪問的數據存儲在ResultID:訪問數據
public class ResultPanelEventArgs : EventArgs
{
private string stringResultId = string.Empty;
private int intRowIndex = -1;
private string stringAnalysisName = string.Empty;
private DateTime dateTimeAnalysisDateTime;
/// <summary>
/// Gets or sets the row index of selected result.
/// </summary>
public int RowIndex
{
get { return intRowIndex; }
set { intRowIndex = value; }
}
/// <summary>
/// Gets or sets the result id of selected result.
/// </summary>
public string ResultId
{
get { return stringResultId; }
set { stringResultId = value; }
}
/// <summary>
/// Gets or sets the date and time of the selected result.
/// </summary>
public DateTime AnalysisDateTime
{
get { return dateTimeAnalysisDateTime; }
set { dateTimeAnalysisDateTime = value; }
}
/// <summary>
/// Gets or sets the name of the sample as Analysis name.
/// </summary>
public string AnalysisName
{
get { return stringAnalysisName; }
set { stringAnalysisName = value; }
}
};
我要拉信息的方法:
private string GetResultID(object sender, ResultPanelEventArgs e)
{
string resultID = string.Empty;
resultID = e.ResultId.ToString();
return resultID;
}
,但似乎無法調用該方法(我得到參數錯誤)。我對c#有點新,並且從來沒有用過EventArgs,所以我甚至不知道這是否可行。有關如何訪問此處存儲的數據的任何建議?
每請求,這裏是出現填充ResultId三種方法:
private ResultPanelEventArgs GetDataForTheGivenRowIndex(int intRowIndex)
{
ResultPanelEventArgs resultPanelEventArgs = new ResultPanelEventArgs();
resultPanelEventArgs.RowIndex = intRowIndex;
try
{
if (intRowIndex >= 0 && intRowIndex < dataGridViewResultView.Rows.Count)
{
object objectResultId = null;
if (dataGridViewResultView.Columns.Contains("ColumnResultId") == true)
{
objectResultId = dataGridViewResultView.Rows[intRowIndex].Cells["ColumnResultId"].Value;
}
else
{
objectResultId = dataGridViewResultView.Rows[intRowIndex].Tag;
}
if (objectResultId != null)
{
resultPanelEventArgs.ResultId = objectResultId.ToString();
}
object objectAnalysisName = null;
if (dataGridViewResultView.Columns.Contains("ColumnAnalysis") == true)
{
objectAnalysisName = dataGridViewResultView.Rows[intRowIndex].Cells["ColumnAnalysis"].Value;
}
else
{
objectAnalysisName = dataGridViewResultView.Rows[intRowIndex].Tag;
}
if (objectAnalysisName != null)
{
resultPanelEventArgs.AnalysisName = objectAnalysisName.ToString();
}
object objectAnalysisDateTime = null;
if (dataGridViewResultView.Columns.Contains("ColumnDate") == true)
{
objectAnalysisDateTime = dataGridViewResultView.Rows[intRowIndex].Cells["ColumnDate"].Value;
}
else
{
objectAnalysisDateTime = dataGridViewResultView.Rows[intRowIndex].Tag;
}
if (objectAnalysisDateTime != null)
{
resultPanelEventArgs.AnalysisDateTime =
Utilities.ConvertStringToDateTime(objectAnalysisDateTime.ToString());
}
}
}
catch
{
resultPanelEventArgs = null;
//Nothing to do
}
return resultPanelEventArgs;
}
和
private ResultPanelEventArgs GetDataForTheGivenResultID(string stringResultId)
{
ResultPanelEventArgs resultPanelEventArgs = null;
try
{
foreach (DataGridViewRow dataGridViewRow in dataGridViewResultView.Rows)
{
if (dataGridViewRow != null)
{
if (dataGridViewRow.Index >= 0)
{
if (dataGridViewRow.Cells["ColumnResultId"] != null)
{
if (dataGridViewRow.Cells["ColumnResultId"].Value.ToString() == stringResultId)
{
//Create the ResultPanelEventArgs
object objectResultId = dataGridViewRow.Cells["ColumnResultId"].Value;
object objectAnalysisName = dataGridViewRow.Cells["ColumnAnalysis"].Value;
object objectAnalysisDateTime = dataGridViewRow.Cells["ColumnDate"].Tag;
resultPanelEventArgs = new ResultPanelEventArgs();
if (objectResultId != null)
{
resultPanelEventArgs.RowIndex = dataGridViewRow.Index;
resultPanelEventArgs.ResultId = objectResultId.ToString();
resultPanelEventArgs.AnalysisName = objectAnalysisName.ToString();
resultPanelEventArgs.AnalysisDateTime = (DateTime)objectAnalysisDateTime;
}
dataGridViewRow.Selected = true;
break;
}
}
}
}
}
}
catch
{
resultPanelEventArgs = null;
//Nothing to do
}
return resultPanelEventArgs;
}
和
private void dataGridViewResultList_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
{
try
{
if (e.RowIndex >= 0)
{
this.result = this.GetResult(e.RowIndex);
ResultPanelEventArgs resultPanelEventArgs = new ResultPanelEventArgs();
resultPanelEventArgs.ResultId = this.result.Id.ToString();
resultPanelEventArgs.RowIndex = this.dataGridViewResultList.SelectedRows[0].Index;
if (this.DoubleClicked != null)
{
this.DoubleClicked(sender, resultPanelEventArgs);
}
this.DialogResult = DialogResult.OK;
}
}
catch (Exception ex)
{
UICommon.LogError(ex);
}
}
你能同時提供你在哪裏填充事件參數的ResultID財產的例子嗎? – neontapir
neontapir,我添加了你要求的方法。 – willkk