Hi,
I have a DataGridView where I have designed in the designer at design time. One of my columns is defined as a DataGridViewComboBoxColumn . At run time, I m trying to fill this ComboBox and not having much luck. Below is my latest attempt at doing so, but when I run the code, the ComboBox is still empty.
I have a DataGridView where I have designed in the designer at design time. One of my columns is defined as a DataGridViewComboBoxColumn . At run time, I m trying to fill this ComboBox and not having much luck. Below is my latest attempt at doing so, but when I run the code, the ComboBox is still empty.
C#:
private void frmReporting_Load(object sender, EventArgs e)
{
dt = Populate("SELECT DISTINCT OperatorName FROM tblOperator WHERE Active='1' ORDER BY OperatorName");
dgvCmbCell = (DataGridViewComboBoxCell)dgvReports[1, 0];
FillComboBox();
}
private DataTable Populate(string sqlCommand)
{
myConnection.Open();
SqlCommand command = new SqlCommand(sqlCommand, myConnection);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = command;
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
adapter.Fill(table);
myConnection.Close();
return table;
}
private void FillComboBox()
{
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
ArrayList row = new ArrayList();
foreach (DataRow dr in dt.Rows)
{
row.Add(dr[0].ToString());
}
dgvCmbCell.Items.Clear();
dgvCmbCell.DataSource = null;
dgvCmbCell.Items.AddRange(row.ToArray());
}