Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having a dictionary.

I want to shown only the keys in the datagridview without binding the values.

How to do so
Posted
Comments
Dinesh.V.Kumar 13-Mar-14 3:15am    
Use the GetEnumerator() to get the keys in to a list object and bind the list object to the datagridview...

Regards
KUMAR619 13-Mar-14 3:18am    
Can you explain with code snippet
Dinesh.V.Kumar 13-Mar-14 3:26am    
List<string> lstKey = new List<string>();
foreach(var entry in dictionary)
{
lstKey.Add(entry.Key);
}
datagridview.DataSource=lstKey;
datagridview.DataBind();

Regards,
KUMAR619 13-Mar-14 5:28am    
Is there any way to bind datagridview without any datasource

1 solution

So you have to have a code similar like in the next example in your Page_Init():
C#
_storagePlanDropDownList.DataSource = dictionary;
                   _storagePlanDropDownList.DataValueField = "key";
                   _storagePlanDropDownList.DataTextField = "key";
                   _storagePlanDropDownList.DataBind();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900