DataGridView column type C #


I have a DataGrid with a DataGridViewComboBoxColumn column, but I want to pass it to the DataGridViewTextBoxColumn column type, so I do the following

if (miDataTable.Rows.Count > 0);
                    // elimina la columna de un data grid

                    // crea una columna 
                    var column = new DataGridViewTextBoxColumn();
                    column.Name = "pCita";
                    column.HeaderText = "Cita #1";

                    //agrega una columna al data grid
                    dgvCitas.Columns.Insert(2, column);


The problem is that this code is within a cycle and every time I delete the column and I create a new one deleting the same data as I may have, so I take care to help me do something similar to this (It should be mentioned that the following code does not work, syntax error) .

if (miDataTable.Rows.Count > 0 && dgvCitas.Columns[numCita].ValueType.ToString()="DataGridViewComboBoxColumn") ;
\ mi codigo

That is to say, I take care that they help me to compare the type of column that it is, because if it is of texbox type it should not enter the if

asked by Magdiel Hernandez 19.11.2018 в 18:12

1 answer


This answers my question, I hope someone is useful to you.

That compares if a datagrid column is a ComboBox type.

if (dgvCitas.Columns[numCita].GetType().ToString() == "System.Windows.Forms.DataGridViewComboBoxColumn")
        \ nuestro codigo
answered by 21.11.2018 в 09:49