2013-10-31 5 views
0

때로는 내 DB의 새 레코드가 이전과 거의 같습니다. 마지막으로 새 레코드를 만드는 "Create From Last"버튼을 만들고 싶습니다 (첫 번째 rec가 아닌 경우).현재 레코드의 새 레코드

내가 좋아하는 뭔가를 시도하고있다 : object rec = BindingSource1.Current; BindingSource1.Add(cur);

하지만 난이 오류가 점점 오전 :

A first chance exception of type 'System.ArgumentException' occurred in System.Data.dll

Additional information: Cannot add external objects to this list.

+0

당신은보고에서이하실 수 있습니다 : http://stackoverflow.com/questions/78536/deep-cloning-objects-in-c-를 날카로운 – NoChance

+0

나는 그것과 함께 약간의 도움이 필요하다 – Theodoros

+0

pls는 더 많은 정보를 제공한다. 당신의 사건에 대해서 - Thx. – NoChance

답변

0

마지막으로 내가 대답을 발견!

난 내 BindingSource1의 .AddingNew 이벤트를 사용하고

private void BindingSource1_AddingNew(object sender, AddingNewEventArgs e) 
     { 
    if(need_insert_from_Current) 
       { 
       BindingSource bs =(BindingSource)sender; 
       DataRowView cur = (DataRowView)bs.Current; 
       DataView dv=(DataView)bs.List; 
       DataRowView drv=dv.AddNew(); 
       // Collect data from current rec (except from the 1st value (Id is Identity !) 
       for (int i = 1; i <= dv.Table.Columns.Count-1; i++) 
       { 
        drv.Row[i] = cur.Row[i]; 
       } 
       bs.Position = bs.Count - 1; 
       e.NewObject = drv; 
       need_insert = true; 
       need_insert_from_Current=false; 
       } 
     } 
관련 문제