简体   繁体   中英

C# Make Combobox inside DataGridView uneditable

I'm facing a problem with generic Comboboxes inside a DGV. After a user chooses a value from a combobox which he had chosen already before, the specific row should become read-only. Just setting the complete row to read-only leads to an Exception from Windows.Forms.dll. The problem is, the combobox can't be set to read-only.

  1. The user choses a value from the first combobox.
  2. Then the user choses the same value again from the combobox in the next row

Is there a way to disable, hide or make the specific combobox unclickable for the user? Just deleting the row does work, as long as the user doesn't use TAB or ENTER, then the whole APP crashes...any suggestions?


EDIT #1: I tried to - instead of disable the ComboBox - remove the complete (duplicate) row. If the user clicks into the next cell, after selecting a value from a combobox, the current cell is removed correctly. But if the user uses the Keyboard, eg TAB or ENTER, to jump out of the combobox-cell, the row is removed and the programm crashes with a Null Reference Exception.

Application.Run(new FormComboBox()); // NULL Reference Exception ?!

So now the problem is the removal of a row, when the user tabs out..

Read my comment again, I suggested to remove the selected item from combobox not the row itself. – Sriram Sakthivel Oct 9 at 7:29

Removing the selected item from the combobox solved my issue. Thanks!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM