다른 양식의 데이터 격자보기에서 데이터를 보는 텍스트 상자가있는 양식이 있습니다. 양식이 열리면 테이블의 선택된 데이터가 텍스트 상자에 표시되고 텍스트를 읽을 수 있도록 잘라냅니다. 버튼을 통해이 양식에서 데이터베이스의 데이터를 삭제하고 양식을 닫을 수있는 버튼이 있습니다. 수정 버튼이있어서 텍스트 상자의 텍스트를 변경하고 저장을 클릭 할 수 있습니다. 지금까지 편집을 클릭하면 닫기 단추 텍스트가 취소로 바뀌지 만 여전히 양식을 닫습니다. 이것이 내가 원하는 것입니다. 업데이트 버튼의 텍스트를 변경하고 싶습니다. 클릭하면 데이터를 업데이트합니다. 하나의 버튼에 2 개의 ClickEvent를 가질 수 있습니까? 하나는 편집을 시작하고 다른 하나는 레코드를 업데이트 할 수 있습니까? 또는 숨겨진 버튼 표시와 수정 버튼을 숨기는 것이 더 좋을까요?ClickEvent Query
void MyButtonClicked(object sender, EventArgs e) {
if(((Button)sender).Text == "Save"){
// do this
} else {
// do that
}
}
는 그러나, 나는 나쁜 형식에서 찾기 :
public partial class viewForm : Form
{
DataRowView Data = null;
public viewForm(DataRowView dr)
{
InitializeComponent();
Data = dr;
}
private void closeBTN_Click(object sender, EventArgs e)
{
this.Close();
}
private void viewForm_Load(object sender, EventArgs e)
{
refTxt.Text = Data["Reference"].ToString().Trim();
firstTxt.Text = Data["First Name"].ToString().Trim();
surenameTxt.Text = Data["Surename"].ToString().Trim();
address1Txt.Text = Data["Address Line 1"].ToString().Trim();
address2Txt.Text = Data["Address Line 2"].ToString().Trim();
countyTxt.Text = Data["County"].ToString().Trim();
postTxt.Text = Data["Post Code"].ToString().Trim();
contactTxt.Text = Data["Contact Number"].ToString().Trim();
emailTxt.Text = Data["Email Address"].ToString().Trim();
}
private void deleteBTN_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Customer information will be perminantly deteled. Do you with to continue? ", "Confirm Delete", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
string constring = @"Data Source=|DataDirectory|\LWADataBase.sdf";
string Query = "delete from customersTBL where Reference ='" + this.refTxt.Text + "';";
SqlCeConnection conDataBase = new SqlCeConnection(constring);
SqlCeCommand cmdDataBase = new SqlCeCommand(Query, conDataBase);
SqlCeDataReader myReader;
try
{
conDataBase.Open();
myReader = cmdDataBase.ExecuteReader();
MessageBox.Show("Customer information has been deleted", "Deleted Sucessfully");
while (myReader.Read())
{
}
MessageBox.Show("Please exit the Customers window and re-open to update the table");
this.Close();
//displays a system error message if a problem is found
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void editBTN_Click(object sender, EventArgs e)
{
firstTxt.ReadOnly = false;
surenameTxt.ReadOnly = false;
address1Txt.ReadOnly = false;
address2Txt.ReadOnly = false;
countyTxt.ReadOnly = false;
contactTxt.ReadOnly = false;
emailTxt.ReadOnly = false;
postTxt.ReadOnly = false;
closeBTN.Text = "Cancel";
deleteBTN.Hide();
}
}
코드를 추가 할 수 있습니까? 당신의 텍스트 블록에서 내 눈을 좀 보았습니다. – admdrew
모든 양식 코드 (지금까지)가 추가되었습니다 – user3237403
아니요 클릭 버튼에 대해 하나의 이벤트 만있을 수 없습니다. – Steve