dataGridView绑定Dictionary |Dictionary绑定到DataGridView

Dictionary<string, string> dic = TaskDAL.GetList(hashId.ToString(), keys);
dataGridView1.DataSource = (from v in dic
                            select new
                            {
                               Key = v.Key,
                               Value = v.Value,
                               time = GetTime(v.Key.Substring(v.Key.LastIndexOf("_") + 1)),
                               str = "hget " + hashId + " " + v.Key
                            }).ToArray();

//这样绑定后,显示的时候,列的宽度可能不是我们想要的样式,所以可以在代码中指定每一列的宽度。
dataGridView1.Columns[
0].Width = 600; dataGridView1.Columns[2].Width = 120; dataGridView1.Columns[3].Width = 250;

 

posted on 2013-03-29 07:37  。!  阅读(1561)  评论(0编辑  收藏  举报