none
change type of datagridview cell from textbox to combobox

    Question

  • PropertiesGrid.Rows(1).Cells.Item(1).Gettype returns System.Windows.Forms.DataGridViewTextBoxCell"} System.Type

    how could I turn that into a combobox for that specific cell - row 1,  column 1?

    Thank you,

    -Greg

    Friday, March 16, 2007 9:05 PM

Answers

All replies

  • this.dataGridView1[1, 1] = new DataGridViewComboBoxCell();
    Friday, March 16, 2007 9:46 PM
  • so simple! Thank you !

    how would I refer to that to populate the combobox with values, or handle selection events?

    Dim cb As New DataGridViewComboBoxCell

    Me.PropertiesGrid(1, 1) = cb

    ok.  cb.Items.Add( xxxxx)

    Thanks again! -Greg

    Saturday, March 17, 2007 12:09 AM
  • I am trying to change the cell type from DataGridViewTextBoxCell to DataGridViewCheckBoxCell @ runtime as below:

     

    DataGridViewCheckBoxCell chkBoxCell = new DataGridViewCheckBoxCell();

    FeatureGridView[1, 1] = chkBoxCell;

     

    However, the application crashes everytime while painting the control giving the following error:

     

    ------------------------------------------------------

    DataGridView Default Error Dialog

    ------------------------------------------------------

    The following exception occurred in the DataGridView: System.FormatException: Formatted value of the cell has a wrong type. To replace this default dialog please handle the DataError event.

     

    Can you please help me in resolving this error ?

     

     

     

     

    Wednesday, November 19, 2008 7:16 AM
  • I'm perplexed as to why this works (simplified VB code):

    For cell As Integer = 1 to n
        Dim cboCell As New DataGridViewComboBoxCell
        myDataGridView(1, n) = cboCell
    Next cell

    While this doesn't:

    row = myDataGridView.Rows(1)
    For Each cell As DataGridViewCell In row.Cells
        Dim cboCell As New DataGridViewComboBoxCell
        cell = cboCell
    Next cell

    myDataGridView(1, n) in the first version and cell in the second both resolve to type System.Windows.Forms.DataGridViewTextBoxCell prior to the conversion.

    The second version doesn't throw an error but it doesn't do anything to the DGV either.

    Can anyone shed any light on what the difference is or what I'm doing wrong? I could use the working version but I'm mystified as to why the more elegant, robust solution fails. (Note: the code is simplified - I populate the combo before assigning it to the cell in both cases in the real code.)

    Thursday, December 03, 2009 7:50 AM
  • If you change Cell type at run time it will throw exception.. to resolve trty this one.....

    Suppose you want to chage celltype of   Dgv.Rows(7).Cells(0)


    Dim CboCell as New DatagridviewComboboxcell
    CboCell.value =nothing
    'Above statement is important if yor r converting to checkcell then set
    'Default value 0

    Dgv.Rows(7).Cells(0) =CboCell
    Dgv.Rows(7).Cells(0) .valuetype = cbocell.valuetype
    Thanks




    Thursday, February 04, 2010 2:41 PM

  • Now I'll try it, Thanks for your reply! Here is also the same case.
    Thursday, January 27, 2011 12:30 AM