|
|
|
winApp C# สอบถามวิธี เช็ค BindingSource ว่ามีการ เปลี่ยนแปลงข้อมูลหรือปล่าว ครับ |
|
|
|
|
|
|
|
Code (C#)
private void frmTest_Bindingsource_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the '_Asset_2DataSet.Person' table. You can move, or remove it, as needed.
this.personTableAdapter.Fill(this._Asset_2DataSet.Person);
}
private void personBindingSource_AddingNew(object sender, AddingNewEventArgs e)
{
richTextBox1.Text += "\n personBindingSource_AddingNew " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);
}
private void personBindingSource_CurrentChanged(object sender, EventArgs e)
{
richTextBox1.Text += "\n personBindingSource_CurrentChanged " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);
}
private void personBindingSource_BindingComplete(object sender, BindingCompleteEventArgs e)
{
richTextBox1.Text += "\n personBindingSource_BindingComplete " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);
}
private void personBindingSource_CurrentItemChanged(object sender, EventArgs e)
{
richTextBox1.Text += "\n personBindingSource_CurrentItemChanged " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);
}
private void personBindingSource_ListChanged(object sender, ListChangedEventArgs e)
{
richTextBox1.Text += "\n personBindingSource_ListChanged " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);
}
ผมลองใช้ทั้ง ListChanged, CurrentItemChanged,CurrentChanged แต่ติดตรงที่มันรัน event ตั้งแต่ เรา Binding มาตั้งแต่แรกเลยครับ
Tag : .NET, Win (Windows App), C#, VS 2013 (.NET 4.x)
|
|
|
|
|
|
Date :
2018-11-13 22:44:11 |
By :
lamaka.tor |
View :
701 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้แล้วครับ ขออนุญาติแปะโค้ดไว้นะครับ(นั่งงมทั้งวัน 5555)
Code (C#)
public static DataTable ToDataTable(this DataGridView dgv)
{
DataTable dt;
if (dgv.DataSource is BindingSource)
dt = ((BindingSource)dgv.DataSource).ToDataTable();
else if (dgv.DataSource is DataSet)
dt = ((DataSet)dgv.DataSource).Tables[dgv.DataMember];
else if (dgv.DataSource is DataTable)
dt = (DataTable)dgv.DataSource;
else
dt = null;
return dt;
}
public static DataTable ToDataTable(this BindingSource bs)
{
var bsFirst = bs;
while (bsFirst.DataSource is BindingSource)
bsFirst = (BindingSource)bsFirst.DataSource;
DataTable dt;
if (bsFirst.DataSource is DataSet)
dt = ((DataSet)bsFirst.DataSource).Tables[bsFirst.DataMember];
else if (bsFirst.DataSource is DataTable)
dt = (DataTable)bsFirst.DataSource;
else
return null;
if (bsFirst != bs)
{
if (dt.DataSet == null) return null;
dt = dt.DataSet.Relations[bs.DataMember].ChildTable;
}
return dt;
}
public static bool HasChanges(this BindingSource bs)
{
bool Result = false;
bs.EndEdit();
Result = (bs.ToDataTable()).GetChanges(DataRowState.Modified) != null;
return Result;
}
|
|
|
|
|
Date :
2018-11-14 17:54:31 |
By :
lamaka.tor |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|