Jump to content

Kastamonolu

Yeni Üye
  • Posts

    3
  • Joined

  • Last visited

About Kastamonolu

Recent Profile Visitors

293 profile views

Kastamonolu's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. C# Excelde ki verileri datagridview'e kopyalama da bekletme Merhabalar, Yazdığım bir tane program var bu program excelde kopyaladığımız verileri datagridview'e yapıştırması lazım aşağıda atacağım kod yapıştırıyor ancak 50-100 arasındaki verileri anında ekliyor diğer yani büyük verileri 10000-20000 gibi verileri eklerken program "Yanıt Vermiyor" durumuna düşüyor. Fakat 3-4 dk sonra program düzeliyor ve verileri yapıştırmış oluyor. Bu bekletme olayını neden yapıyor veya nasıl çözebilirim? Bana bir yol önerirmisiniz. try { IDataObject obj = Clipboard.GetDataObject(); string s = Clipboard.GetText(); string[] lines = s.Split('\n'); int iFail = 0; bool headerSelected = false; if (dataGridView1.CurrentRow != null) { headerSelected = dataGridView1.CurrentRow.Selected; } int iCol = dataGridView1.ColumnCount - 1, iRow = dataGridView1.RowCount - 1; foreach (DataGridViewCell cell in dataGridView1.SelectedCells) { if (cell.ColumnIndex < iCol || cell.RowIndex < iRow) { iCol = cell.ColumnIndex; iRow = cell.RowIndex; } } foreach (string line in lines) { if (line.Length > 0) { if (iRow < dataGridView1.RowCount) { string[] sCells = line.Split('\t'); int offset = 0; for (int i = 0; (headerSelected ? i + 1 : i) < sCells.GetLength(0); ++i) { if (iCol + i < dataGridView1.ColumnCount) { while (!dataGridView1[iCol + i + offset, iRow].Visible && iCol + i + offset + 1 < dataGridView1.ColumnCount) { offset++; } if (dataGridView1[iCol + i + offset, iRow].Visible) { try { dataGridView1.CurrentCell = dataGridView1[iCol + i + offset, iRow]; } catch { ; } if (!dataGridView1.CurrentCell.ReadOnly) { string value = headerSelected ? sCells[i + 1] : sCells[i]; if (dataGridView1.CurrentCell.Value == null || dataGridView1.CurrentCell.Value.ToString() != value) { dataGridView1.BeginEdit(true); if (dataGridView1.EditingControl != null) { dataGridView1.EditingControl.Text = value; } else { dataGridView1.CurrentCell.Value = Convert.ChangeType(sCells[i], dataGridView1.CurrentCell.ValueType); } dataGridView1.NotifyCurrentCellDirty(true); dataGridView1.EndEdit(); } } else { iFail++; } } else { iFail++; } } } iRow++; } } else { break; } if (iFail > 0) { MessageBox.Show(string.Format("{0} güncellemeleri " + " yalnızca sütun ayarını okumak için başarısız oldu ", iFail)); } } } catch (FormatException) { MessageBox.Show("Yapıştırdığınız veriler hücrenin yanlış biçimindedir.", "Hata Penceresi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
  2. İf le bitireceksin C# olanı yapıp atayım istersen :D
  3. Bu katılımsız olarak sunduklarında süre sınırı varmı?
×
×
  • Create New...