This is my requirement: I have a datagridview which should be populated with employee shift data from shift details which is available in sch.shift_detailsList(entity model-shift). For eg: shift for 1 week(nov 1 to nov 7) is saved in sch.shift_detailsList.So in the datagridview if the weekcount=2(ie shift to be saved for 2 weeks, ie cycledays=7*2 -1=13) , the bindingsource1(for the datagridview) should be populated with shift for 2 weeks, ie if start date given as nov1, then the shift details in sch.shift_detailsList should be repeated for the 2nd week also. So, when the loop finishes the 1st week and then i=7, and again it should start from first item of sch.shift_detailsList and the 8th entry in bindingSource1 (8) date should be nov 8th .but my issue is that now, the date in bindingSource1 (0) and sch.shift_detailsList (0) also becomes set to nov 8th. I dont know why this is happening.I would really appreciate if Anybody can help me please.
Question
serenaa
Hi all,
This is my requirement: I have a datagridview which should be populated with employee shift data from shift details which is available in sch.shift_detailsList(entity model-shift). For eg: shift for 1 week(nov 1 to nov 7) is saved in sch.shift_detailsList.So in the datagridview if the weekcount=2(ie shift to be saved for 2 weeks, ie cycledays=7*2 -1=13) , the bindingsource1(for the datagridview) should be populated with shift for 2 weeks, ie if start date given as nov1, then the shift details in sch.shift_detailsList should be repeated for the 2nd week also. So, when the loop finishes the 1st week and then i=7, and again it should start from first item of sch.shift_detailsList and the 8th entry in bindingSource1 (8) date should be nov 8th .but my issue is that now, the date in bindingSource1 (0) and sch.shift_detailsList (0) also becomes set to nov 8th. I dont know why this is happening.I would really appreciate if Anybody can help me please.
List<Model.Shiftdetails> schdetails = new List<Model.Shiftdetails>();
bindingSource1.DataSource = schdetails;
gridControl1.DataSource = bindingSource1;
int k=0;
for (int i = 0,j=0; i <=cycledays; i+=7)
{
foreach (Model.Shiftdetails detail in sch.shift_detailsList)
{
Model.Shiftdetails cycleschdetails = new Model.Shiftdetails();
cycleschdetails = detail;
cycleschdetails.shift_date = dtCycleStartDate.DateTime.Date.AddDays(j);
j++;
k++;
if (cycleschdetails.schedule == null)
{
cycleschdetails.schedule = new Model.Schedule { id = -1, schedule_info = new Model.ScheduleInfo { schedule_name = crm.GetString("NoShift") }, schedule_flexible = true };
}
bindingSource1.Add(cycleschdetails);
bindingSource1.MoveNext();
if (k > cycledays)
break;
}
if (k > cycledays)
break;
}
Thanks
Link to comment
Share on other sites
1 answer to this question
Recommended Posts