public static void DataGridViewAddRow(DataGridView ctrl, params object[] args) { if (ctrl.InvokeRequired) { DataGridViewAddRowDelegate del = new DataGridViewAddRowDelegate(DataGridViewAddRow); ctrl.Invoke(del, args); } else { ctrl.Rows.Add(args); } }
public void DataGridViewAddRow(string host) { if (dataGridView.InvokeRequired) { // this is worker thread DataGridViewAddRowDelegate delegateAddRow = new DataGridViewAddRowDelegate(DataGridViewAddRow); dataGridView.Invoke(delegateAddRow, host); } else { // this is UI thread // formating data host = host.Replace("\t", ""); host = host.Replace("\r\n", ""); host = host.Replace(" ", ""); // add line. if (!string.IsNullOrEmpty(host)) { dataGridView.Rows.Add(host); } } }