업데이트 버튼을 누른 후 WinGridView를 업데이트하는 데 문제가 있습니다. INotifyPropertyChanged 속성을 사용하여 BindingList를 사용하고 있습니다. 그리고 여전히 내 gridview를 업데이트 할 수 없습니다. 다음은BindingList로 wingridview 업데이트
내 짧은 테스트 프로그램에서 코드입니다 :
public Form1()
{
InitializeComponent();
//create BindingList
using(SqlConnection connection = new SqlConnection(SQLconnectionString))
{
connection.Open();
using(SqlCommand command = new SqlCommand(SelectCustomer, connection))
{
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
customerList.Add(new Customers(reader["CntId"].ToString(), reader["Name"].ToString(), reader["Surname"].ToString()));
}
}
}
}
customersBindingSource = new BindingSource(customerList, null);
ugv_contacts.DataSource = customersBindingSource;
}
//update button
private void btn_UpdateCustomer_Click(object sender, EventArgs e)
{
using (SqlConnection conDataBase = new SqlConnection(SQLconnectionString))
{
try
{
conDataBase.Open();
SqlCommand updateCommand = conDataBase.CreateCommand();
updateCommand.CommandText = UpdateCustomerDet;
updateCommand.Parameters.AddWithValue("@CntId", Customer_Id);
updateCommand.Parameters.AddWithValue("@CntSurname", txt_surname.Text);
updateCommand.Parameters.AddWithValue("@CntName", txt_name.Text);
SqlDataReader myReader;
myReader = updateCommand.ExecuteReader();
customersBindingSource.ResetBindings(false);
}
catch (Exception ex) //v primeru napake se izvede to
{
MessageBox.Show(ex.Message);
}
}
}
public class Customers : INotifyPropertyChanged
{
public Customers(string id, string surname, string name)
{
CntId = id;
Name = name;
Surname = surname;
}
private string id;
private string surname;
private string name;
public string CntId { get { return id; } set { id = value; NotifyPropertyChanged("CntId"); } }
public string Surname { get { return surname; } set { surname = value; NotifyPropertyChanged("Surname"); } }
public string Name { get { return name; } set { name = value; NotifyPropertyChanged("Name"); } }
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string p)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(p));
}
}
사람은 throught를 가서 내가 잘못하고있는 무슨 얘기시겠습니까? 검색 및 stackoverflow 많은 질문을 테스트 한 여전히 올바르게 작동하도록 내 코드를 만들 수 없습니다.
귀하는 고객의 자산을 변경 한 코드를 게시하지 않았습니다. – LarsTech
그게 내가 없기 때문입니다. :)이 개념은 완전히 새로운 것이기 때문에 나는이 개념을 이해하는데 어려움을 겪고있다. 어떻게 더 진행해야합니까? 감사합니다. – Urban
버튼 업데이트로 변경합니다. 그게 당신이 염두에두고있는 것입니까? – Urban