在使用DataLayoutControl结合DataNavigator形成编辑界面时,对新增行赋初值不同于XtraGrid的做法,不能通过在DataNavigator的ButtonClick事件里判定Append按钮来实现,而是要通过BindingSource的ListChanged事件来进行。
private void provinceBindingSource1_ListChanged(object sender, ListChangedEventArgs e)
{
if (e.ListChangedType == ListChangedType.ItemAdded)
{
LASystemDataSet.ProvinceRow row = (provinceBindingSource1[e.NewIndex] as DataRowView).Row as LASystemDataSet.ProvinceRow;
row.PK_Province = Guid.NewGuid();
}
}
The ListChanged event occurs when there is a change to the membership or metadata of the underlying list represented by the List property. For example, this event is raised when items are added, removed, or moved, or the DataSource or DataMember properties change. The values of the Sort and Filter properties will persist when this event occurs.
This event can be completely suppressed by setting the RaiseListChangedEvents property to false. For more information about handling events, see Consuming Events.