So I have a datagrdview whose data is dynamically changed and filled using datatables. The reason for using DataTable is because I change up what is in the DataGridView throughout the course of the code. What I'm trying to accomplish is by using a DataTable I want the user to be able to Update changes made to the database. This works if I leave it as a textbox, however, as the data is a set amount of options, I would like to be able to make the columns be comboboxes.
Curtrently this is what I have:
this.StoresDataGrid.Rows.Clear();
StoresTable = new DataTable("ItemsTable");
StoresTable.Columns.Add("Meter Number", typeof(String));
StoresTable.Columns.Add("Manufacturer", typeof(ComboBox));
StoresTable.Columns.Add("Meter Size", typeof(String));
StoresTable.Columns.Add("Model Number", typeof(String));
StoresTable.Columns.Add("Body Type", typeof(String));
StoresTable.Columns.Add("Location", typeof(String));
StoresTable.Columns.Add("Account Number", typeof(String));
StoresTable.Columns.Add("Premise ID", typeof(String));
StoresTable.Columns.Add("Date Created", typeof(String));
StoresTable.Columns.Add("Created By", typeof(String));
StoresTable.Columns.Add("Invoice Number", typeof(String));
StoresTable.Columns.Add("Seal Number", typeof(String));
StoresTable.Columns.Add("Meter Status", typeof(String));
StoresTable.Columns.Add("Stolen", typeof(String));
StoresTable.Columns.Add("Verified", typeof(String));
using (SqlConnection GetItemCon = new SqlConnection(ConfigurationManager.ConnectionStrings["ConfigString"].ToString()))
using (SqlCommand GetItemCom = GetItemCon.CreateCommand())
{
GetItemCom.CommandText = GetItemsQuery;
adapter = new SqlDataAdapter(GetItemsQuery, GetItemCon);
GetItemCon.Open();
using(SqlDataReader GetItemsRead = GetItemCom.ExecuteReader())
{
while (GetItemsRead.Read())
{
manuBox.SelectedItem = GetItemsRead["meter_make"].ToString();
StoresTable.Rows.Add(GetItemsRead["meter_number"].ToString(), manuBox, GetItemsRead["meter_size"].ToString(), GetItemsRead["model_number"].ToString(),
GetItemsRead["body_type"].ToString(), GetItemsRead["current_location"].ToString(), GetItemsRead["acct_num"].ToString(), GetItemsRead["premise_id"].ToString(),
GetItemsRead["date_created"].ToString(), GetItemsRead["created_by"].ToString(), GetItemsRead["batch_number"].ToString(), GetItemsRead["seal_number"].ToString(),
GetItemsRead["meter_status"].ToString(), GetItemsRead["stolen"].ToString(), GetItemsRead["verified"].ToString());
}
adapter = new SqlDataAdapter(GetItemsQuery, GetItemCon);
StoresDataGrid.DataSource = StoresTable;
StoresDataGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
}
GetItemCon.Close();
((DataTable)StoresDataGrid.DataSource).AcceptChanges();
}
I have no errors however the assigned column does not become a "ComboBox" like I'd like. How can I achieve this using DataTable? Can I achieve this using DataGridView and still be able to tie it to a DataTable?