Что я пытаюсь сделать, это выбрать строку в сетке данных, а затем скопировать данные в выбранной строке в другие строки (которые уже существуют, но не имеют данных в различных столбцах) в сетке данных. Одним из столбцов является DateTime. Когда процесс завершается, текстовое поле (Bill of Lading #) копируется очень хорошо, но поле DateTime выдает только «MM / dd / yyyy».
Вот как это выглядит до начала копирования: ![enter image description here](https://i.stack.imgur.com/Ku8oz.png)
![enter image description here](https://i.stack.imgur.com/Vor2t.png)
Я попытался преобразовать значение из строки источника (на изображении строка источника - это первая строка в сетке и значение 4/15/2020) в строку, к дате и т. д. c. Неважно, что он только когда-либо показывает формат.
_fireCellValueChanged = false;
//iterate through the selected rows and copy the shipping date, bol and destination values
//get the source copy row values
DateTime shipDate = Convert.ToDateTime(dgvSOW.Rows[_checkedSourceRow].Cells[4].Value);
//string shipDate = dgvSOW.Rows[_checkedSourceRow].Cells[4].Value.ToString();
string bol = dgvSOW.Rows[_checkedSourceRow].Cells[3].Value.ToString();
byte destination = Convert.ToByte(dgvSOW.Rows[_checkedSourceRow].Cells[5].Value);
foreach (DataGridViewRow row in dgvSOW.SelectedRows)
{
//bol
DataGridViewCell cell = row.Cells[3];
DataGridViewTextBoxCell bolCell = cell as DataGridViewTextBoxCell;
bolCell.Value = bol;
//shipping date
cell = row.Cells[4];
DataGridViewTextBoxCell shipDateCell = cell as DataGridViewTextBoxCell;
// row.Cells[4].Value = rsi.ShippingDate.Value.ToString("d");
shipDateCell.Value = dgvSOW.Rows[_checkedSourceRow].Cells[4].Value.ToString();
//destination / buying customer
DataGridViewComboBoxCell destinationCell = cell as DataGridViewComboBoxCell;
destinationCell = (DataGridViewComboBoxCell)row.Cells[5];
cell.Value = destination;
}
_fireCellValueChanged = true;
_unsavedChanges = true;
btnSave.Enabled = true;
Столбец «Пункт назначения» также не работает, но я подозреваю, что если я смогу решить проблему с датой отгрузки, аналогичное решение для Столбец «Назначение» будет работать. Может быть. Или нет. : - (
Что я здесь не так делаю?