I am binding a List to a UI Control. My list does not contain a blank row, but I need to add one to allow the user to select blank. However, I'm using the same list in other parts of the application (users can edit/add/delete items) where it doesn't make sense to show a blank row.
My idea is to create a wrapper around the list which adds a blank row just for the UI. The wrapper would hold a reference so that updates to the lis开发者_开发百科t (from other parts of the app) would be reflected in UI without any extra work.
I have tried a few different ways, but nothing has worked out for me yet. Can anyone solve this problem?
Assuming you use a Forms.DataGridView, you may use
dataGridView1.ClearSelection();
or let the user deselect rows by holding strg and clicking the selected row (this is standard behavior of the DataGridView)
Then ask for
dataGridView1.SelectedRows.Count == 0
to figure, whether no row is selected, which i would interpret as blank ;)
I have not found an answer to this. My solution was to make a copy of my list and add a 'blank' row.
精彩评论