public void bindDataToGrid(DataGridView grid, AbstractCommonData entity, changingRow chageRow, Hashtable hash) { grid.Rows.Clear(); int columns = grid.ColumnCount; DataTable table = entity.Tables[entity.FilledTableName]; if (table == null) { throw new Exception("نا م جدول در دیتا ست یافت نشد"); } string field; string colName = ""; object value = ""; int currentRowIndex; for (int tableIndex = 0; tableIndex < table.Rows.Count; tableIndex++) { currentRowIndex = grid.Rows.Add(); for (int gridIndex = 0; gridIndex < grid.Columns.Count; gridIndex++) { field = grid.Columns[gridIndex].DataPropertyName; if (field != null && field.Length > 0) { colName = grid.Columns[gridIndex].Name; try { value = getAsString(table.Rows[tableIndex][field]); } catch (Exception ex) { value = ""; } //cell = new DataGridViewCell(); //cell.Value = value; if (colName.Equals("USERTYPE")) { if (grid.Rows[currentRowIndex].Cells[colName] is DataGridViewComboBoxCell) { ((DataGridViewComboBoxCell)grid.Rows[currentRowIndex].Cells[colName]).Value = value; } } else { grid.Rows[currentRowIndex].Cells[colName].Value = value; } } } if (chageRow != null) { chageRow(grid, currentRowIndex, hash); } } }
public void bindDataToGrid(DataGridView grid, DataSet dataset, string tableName, changingRow chageRow, Hashtable hash) { grid.Rows.Clear(); int columns = grid.ColumnCount; DataTable table = dataset.Tables[tableName]; if (table == null) { throw new Exception("نا م جدول در دیتا ست یافت نشد"); } string field; object value = null; int currentRowIndex; for (int tableIndex = 0; tableIndex < table.Rows.Count; tableIndex++) { currentRowIndex = grid.Rows.Add(); for (int gridIndex = 0; gridIndex < grid.Columns.Count; gridIndex++) { field = grid.Columns[gridIndex].Name; if (!field.Equals("SmsSend")) { value = getAsString(table.Rows[tableIndex][field]); } //cell = new DataGridViewCell(); //cell.Value = value; grid.Rows[currentRowIndex].Cells[field].Value = value; } if (chageRow != null) { chageRow(grid, currentRowIndex, hash); } } }