tags:

views:

38

answers:

2

I was wondering if its possible to make a single comboBox not visible or disabled for only that certain row?

right now I have something like

private void gvAirSegment_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
        if (e.ColumnIndex+1 == gvAirSegment.Columns["RemarkLine"].Index)
        {
            if (!gvAirSegment.CurrentCell.Selected)
            {
                gvAirSegment.Columns[2].Visible = true;
            }
            else
            {
                gvAirSegment.Columns[2].Visible = false;
            }
        }
    }

which on click of a checkbox it hides the entire column, but I would like it so only that combobox is not visible/disabled.

If I could get the control that would be the best, if I could turn it into a GridViewComboBox into a comboBox control

Thanks

+2  A: 

You can assign a new instance of the base class DataGridViewCell to the appropriate column and row for any cell you would like to hide from the user:

gvAirSegment.Rows[row].Cells[col] = new DataGridViewCell();

Don't forget to assign a Value, as overwriting the cell will destroy the stored value.

This technique probably won't work if the DataGridView is bound to a data source, or running in virtual mode.

Bradley Smith
+2  A: 

Because the combobox is tied to the cell type, you can't really hide it without hiding the whole cell, if I understand your question. You can, however, set the control to be read-only.

gvAirSegment.Rows[e.RowIndex].Cells[2].ReadOnly = true;
James B
that does work, the readonly isn't working as intended though:( it still looks it should be able to be selected(for end users they will think its just not working)
Spooks
I understand what you mean. I'm afraid those are going to be your only two options... readonly or hide the column completely (or take Brad's suggestion and replace the cell itself).If you want to decouple the combo box from the cell, you'd need to use a control other than DataGridView, and manage your own controls in the grid cells. Probably not be a palatable option (though there are extended grid controls that make it easy to work with child controls)
James B