Click here to Skip to main content
15,888,031 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here is my code to add table to grid view from source code can anyone help me how to bind column names to combobox

C#
string conStr = string.Format("Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={0})(PORT={1})))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME={2})));User Id={3};Password={4}; ", conHostName, conPort, conDatabase, _dbUserName, _dbPwd);
               //OracleConnection con = new OracleConnection(conStr);
               //con.Open();
               // define Command
               using (var conn = new OracleConnection(conStr))
               {
                   DataSet dataset = new DataSet();

                  // create & define the command
                   var cmd = new OracleCommand();
                   cmd.CommandType = CommandType.StoredProcedure;
                   cmd.CommandText = "REPORTS.GET_DAILY_STATUS";
                   cmd.Connection = conn;

                   // Declare parameter for FROM DATE - INPUT
                   OracleParameter param1 = new OracleParameter("PID_FROM_DATE", OracleType.DateTime, 10);
                   param1.Value = Convert.ToDateTime(dateTimePicker1.Value.Date);
                   param1.Direction = ParameterDirection.Input;

                   // add to cmd object
                   cmd.Parameters.Add(param1);

                   // Declare parameter for To DATE - INPUT
                   OracleParameter param2 = new OracleParameter("PID_TO_DATE", OracleType.DateTime, 10);
                   param2.Value = Convert.ToDateTime(dateTimePicker2.Value.Date);
                   param2.Direction = ParameterDirection.Input;

                   // add to cmd object
                   cmd.Parameters.Add(param2);

                   // Declare parameter for spvsr DATE - INPUT
                   OracleParameter param3 = new OracleParameter("PIN_SPVSR_ID", OracleType.Number, 10);
                   param3.Value = 410;
                   param3.Direction = ParameterDirection.Input;

                   // add to cmd object
                   cmd.Parameters.Add(param3);

                   //PORC_DATA 410

                   // Declare parameter for FROM procreport  - OUTPUT
                   OracleParameter param4 = new OracleParameter("PORC_REPORT", OracleType.Cursor);
                   param4.Direction = ParameterDirection.Output;

                   // add to cmd object
                   cmd.Parameters.Add(param4);


                   //OracleParameter[] oprms = new OracleParameter[3];
                   //oprms[0] = new OracleParameter("PIC_FROM_DATE", OracleType.VarChar, 10, dateTimePicker1.Value, ParameterDirection.Input);
                   //oprms[1] = new OracleParameter("PIC_TO_DATE", OracleType.VarChar, 10, dateTimePicker1.Value, ParameterDirection.Input);
                   //oprms[2] = new OracleParameter("PORC_DATA", OracleType.RefCursor, ParameterDirection.Output);
                   //foreach (OracleParameter oprm in oprms)
                   //{
                   //    cmd.Parameters.Add(oprm);
                   //}
                   OracleDataAdapter oDap = new OracleDataAdapter(cmd);
                   oDap.Fill(table);

                   if (table != null)
                   {
                       dataGridView1.AutoGenerateColumns = true;
                       dataGridView1.DataSource = table.DefaultView;

                   }
Posted
Updated 22-May-12 18:31pm
v2

1 solution

You have filled a data table so if you use this data table as a source to a combo box, you set:
- DisplayMember[^]
- ValueMember[^]

If this isn't a separate combobox but a combo box column then use the mentioned properties on DataGridViewComboBoxColumn [^]
 
Share this answer
 
Comments
Member 8983639 23-May-12 0:42am    
it is a separate combobox on the form. now i have stucked up here for (int i = 1; i < dataGridView1.Columns.Count + 1; i++)
{
//ExcelApp.Cells[1, i] = dataGridView1.Columns[i - 1].HeaderText;
comboBox1.DisplayMember = dataGridView1.
}
how to assign combobox the column names now?
Wendelius 23-May-12 0:56am    
Don't quote understand the situation. The combo box has only 1 display member so you cannot define the display member for each datagridview column. Are you trying to create a situation where depending on the selected cell the combo box would show different values. If that is the case, you could set the combo box properties inside CellEnter Event[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900