我已經完成了將數據從DataSet插入到組合框的代碼序列,但它看起來像是很多工作。我想可能有一個更短的路,然後我想到了這個問題。是否有可能將數據集中表格列中的一組行轉換爲可以使用最少編碼工作量輸入組合框的列表?有沒有辦法將數據集轉換爲可用作組合框數據源的列表?
我嘗試過的方法是使用Dataset.Tables [0] .Select()返回一個dataRowCollection,但是這個想法崩潰並燒燬 - 組合框不想接受它。
另一種方法我試過的工作,但它似乎是一個類似的方法,我與我的長碼:
DataSet comboBoxItems = new SQLCommands().GetStockIDs(); //Calls the uspGetStockIDs Stored procedure,Returning 1 Column (StockID from Stock Table)
cbStockID.Items.Clear(); //Clears the Combobox
foreach (DataRow dr in comboBoxItems.Tables[0].Rows) //Then Iterates through the retrieved rows
{
cbStockID.Items.Add(dr.Field<int>(0)); //and places them in the combobox
}
但是上面的代碼並沒有回答我的問題。這是我重新解釋我的問題的地方:是否可以將數據集中表格列中的一組行轉換爲可以使用最少編碼工作輸入到組合框中的列表?
後來檢查答案 - 得跑去購物。 – Eon