コード例 #1
0
 private bool DoFillDown(PropertyDescriptor[] propertyDescriptors, int firstRowIndex, int lastRowIndex)
 {
     bool anyChanges = false;
     var firstRowValues = propertyDescriptors.Select(pd => pd.GetValue(BindingListSource[firstRowIndex])).ToArray();
     for (int iRow = firstRowIndex + 1; iRow <= lastRowIndex; iRow++)
     {
         var row = BindingListSource[iRow];
         for (int icol = 0; icol < propertyDescriptors.Length; icol++)
         {
             var propertyDescriptor = propertyDescriptors[icol];
             try
             {
                 propertyDescriptor.SetValue(row, firstRowValues[icol]);
                 anyChanges = true;
             }
             catch (Exception e)
             {
                 MessageDlg.Show(this, TextUtil.LineSeparate(Resources.DataboundGridControl_DoFillDown_Error_setting_value_,
                     e.Message));
                 var column = DataGridView.Columns.OfType<DataGridViewColumn>()
                     .FirstOrDefault(col => col.DataPropertyName == propertyDescriptor.Name);
                 if (null != column)
                 {
                     DataGridView.CurrentCell = DataGridView.Rows[iRow].Cells[column.Index];
                 }
                 return anyChanges;
             }
         }
     }
     return anyChanges;
 }