dataGridView繫結Dictionary |Dictionary繫結到DataGridView

xuxubaby發表於2013-10-14
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;

相關文章