How to insert 'Empty' field in ComboBox bound to DataTable

后端 未结 13 1320
谎友^
谎友^ 2020-12-14 09:07

I have a combo box on a WinForms app in which an item may be selected, but it is not mandatory. I therefore need an \'Empty\' first item to indicate that no value has been s

相关标签:
13条回答
  • 2020-12-14 09:40

    I found another solution:

    Just after your data table is created (before using fill), add new row and use AcceptChanges method to the table. The new record would get RowState = Unchanged, and would not be added to database, but would be visible in your datatable and combobox.

       DataTable dt = new DataTable();
        dt.Rows.Add();
        dt.AcceptChanges();
        ...
        dt.Fill("your query");
    
    0 讨论(0)
提交回复
热议问题