DataGridViewComboBox selectively hide arrow

P

Paul E

I have a column on my DataGridView that is of the type
DataGridViewComboBoxColumn. On some of my rows, I want to keep the user
from changing the value in that field.

What I'm doing now is, as soon as I populate my rows, I run through
each row something like this:

private: System::Windows::Forms::DataGridView^ Fields;
...
#define COMBO_COL 3

for (int i = 0; i < Fields->RowCount; ++i)
{
if (it shouldn't be changed)
{
Fields->Rows->Cells[COMBO_COL]->ReadOnly = true;
}
}

That works, but it both looks ugly and doesn't give the user a clue
about why the combo box's arrow doesn't do anything.

Ideally, what I'd like to do is hide the arrow altogether for those
rows. Does anyone have any ideas about how to do that?

One thought is that I could change the cell type on the fly to a
regular edit cell. I'm not sure how to do that, or if that would just
confuse the control altogether.
 
R

RobinS

Why would you put a combobox in the grid if you don't want
the user to use it?

Robin S.
 
P

Paul E

RobinS said:
Why would you put a combobox in the grid if you don't want
the user to use it?

I have about 20 rows on my grid. Depending on the data that is in a
particular row, the data in the combobox column may not be changable.
As it turns out, only around a quarter of the rows should allow the
user to change that column. If the combobox's arrow only appeared on
those 4 or so cells, then they would pop out to the user and be
obvious.

To be more concrete, I have 20 rows in my grid. I don't allow the user
to change the data in the first column. It is an edit type column. I do
allow the user to change the data in the second column. It is also an
edit type column. In the third column, I only want to allow the user to
change the data in rows #5, 6,12, and 15. It is a combobox column.

In all the other rows, that is (1,2,3,4,7,8...) I would like to display
the data in column 3 as if it were an edit type column, but in rows
5,6,12, and 15, I want to display the combobox for the user to
manipulate.
 
A

AnikSol

set the combobox column display style to nothing, for the arrows to vanish
and at the same time make those cells read only.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top