DevExpressXtraGridコントロールを備えたメインフォームを持つプログラムがあります。DBからのデータを含む多くの行があります。選択した行を編集するための編集フォームとメインフォームの編集ボタンがあります。選択したオブジェクトの情報を編集フォームに正常に取り込むことができましたが、何らかの理由で、UPDATEコマンドを実行したときに再度実行するのに問題があります。メインフォームで選択した行をとして参照していgridView1.GetFocusedRow()
ます。これはshowAttributesメソッドでは完全に機能しましたが、機能しなくなりました。
私のコードは次のとおりです。'call'がnullであるため、例外が返されます。いくつか注意してください。私は試してみましたが、最初の行を編集しているだけmain.gridView1.Focus()
のmain.gridView1.FocusRowHandle(0)
場合は、どちらも問題を修正しませんでした。これは、行がまだ正しくフォーカスされていることを示しているようですが、参照が何らかの理由で失われました。
Main.csで
private void btnEdit_Click(object sender, EventArgs e)
{
//This is the key, that lets you access an attribute of the selected row.
Object obj = gridView1.GetFocusedRow();
//1) Show NewEdit Form
Edit edit = new Edit();
edit.Show();
//2) Display properties of this object from DB
edit.showAttributes(obj);
}
Edit.csの場合:
private void btnSubmit_Click(object sender, EventArgs e)
{
Main main = new Main();
Object obj = main.gridView1.GetFocusedRow();
try
{
performUpdate(obj);
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex);
}
}
public void performUpdate(Object call1)
{
Main main = new Main();
CallLog call = new CallLog();
call = call1 as CallLog;
executeSQLUpdate(call.Oid);
main.xpServerCollectionSource1.Reload();
}
これがshowAttributesコードです-同じことをしますが機能します
public void showAttributes(Object call1)
{
try
{
Main main = new Main();
CallLog call = new CallLog();
call = call1 as CallLog;
txtCompany.Text = call.CompanyName;
txtFirst.Text = call.FirstName;
txtMiddle.Text = call.MiddleName;
txtLast.Text = call.LastName;
txtPhone.Text = call.PhoneNumber;
txtFax.Text = call.Fax;
txtEmail.Text = call.Email;
txtAttention.Text = call.Attention;
txtCareOf.Text = call.CareOf;
txtAddress1.Text = call.Address1;
txtAddress2.Text = call.Address2;
txtCity.Text = call.City;
txtState.Text = call.State;
txtZip.Text = call.ZipCode;
txtProvince.Text = call.Province;
txtCountry.Text = call.Country;
txtMessage.Text = call.Message;
txtResponse.Text = call.Response;
if (call.VIP == 1) { chkVIP.Checked = true; } else { chkVIP.Checked = false; }
if (call.ThreatCall == 1) { chkThreat.Checked = true; } else { chkThreat.Checked = false; }
if (call.FollowUp == 1) { chkFollowUp.Checked = true; } else { chkFollowUp.Checked = false; }
if (call.EscalationRequired == 1) { chkEscalation.Checked = true; } else { chkEscalation.Checked = false; }
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex);
return;
}
}
また...私はこれを他のいくつかの方法で、パラメータなしで、別の場所などで試しました。問題はmain.gridView1.GetFocusedRow()
nullを返すことです。また、メインフォームから一連のメソッドとして実行することも機能しません(gridView1.GetFocusedRow()
これもnullです)。