---
title: "How to get Combobox.Datasource to a Dictionary?"  
description: "How to get Combobox.Datasource to a Dictionary?"  
author: "Takeshi Okada"  
published: 2014-01-27  
updated: 2014-01-27  
canonical: https://www.mindstick.com/forum/1884/how-to-get-combobox-datasource-to-a-dictionary  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# How to get Combobox.Datasource to a Dictionary?

Following is my code which is [binding](https://www.mindstick.com/blog/146/dynamic-binding-in-c-sharp) a List() to a [ComboBox](https://www.mindstick.com/articles/57/display-record-according-to-combobox-selection-in-csharp-dot-net) [control](https://www.mindstick.com/blog/197/asp-dot-net-repeater-control). I tried to add few items to the CombBox control using [Insert](https://www.mindstick.com/blog/173/executing-insert-delete-or-update-query-in-sqlserver-using-ado-dot-net)() method which is not allowed as it has been assigned to a [datasource](https://www.mindstick.com/blog/447/listing-the-databases-connected-to-the-datasource). So, how can I get the datasouce back to a new [variable](https://www.mindstick.com/articles/1807/objective-c-data-types-variables-object-creation) (say, var colours2) from cmbColour.DataSource which is [returning](https://www.mindstick.com/news/2477/returning-ceo-bob-iger-dismisses-the-disney-apple-sale-as-pure-speculation) an object. Thanx !

var [colours](https://yourviews.mindstick.com/view/80852/how-do-we-celebrate-festival-of-colours-holi)= new [Dictionary](https://www.mindstick.com/articles/1500/hashtable-and-dictionary-in-c-sharp)<[string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp), string>

{

{"1x","Green"},

{"2x","Red"},

{"3y","Blue"},

{"4y","Black"}

}.ToList();

cmbColour.ValueMember = "Key";

cmbColour.DisplayMember = "Value";

cmbColour.DataSource = colours;

var colours2 = //how can I get the DataSource back

## Replies

### Reply by Pravesh Singh

Hi Takeshi,\
Try this:-\

var coloursList = cmbColour.DataSource as List<KeyValuePair<string, string>>;

var colours2 = coloursList.ToDictionary(x => x.Key, x => x.Value);


---

Original Source: https://www.mindstick.com/forum/1884/how-to-get-combobox-datasource-to-a-dictionary

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
