如何将列表绑定到dataGridView?

如何将列表绑定到dataGridView?,第1张

如何将列表绑定到dataGridView?

使用BindingList并设置列的DataPropertyName
-Property。

请尝试以下 *** 作

...private void BindGrid(){    gvFilesOnServer.AutoGenerateColumns = false;    //create the column programatically    DataGridViewCell cell = new DataGridViewTextBoxCell();    DataGridViewTextBoxColumn colFileName = new DataGridViewTextBoxColumn()    {        CellTemplate = cell,         Name = "Value",        HeaderText = "File Name",        DataPropertyName = "Value" // Tell the column which property of FileName it should use     };    gvFilesOnServer.Columns.Add(colFileName);    var filelist = GetFileListonWebServer().ToList();    var filenamesList = new BindingList<FileName>(filelist); // <-- BindingList    //Bind BindingList directly to the DataGrid, no need of BindingSource    gvFilesOnServer.DataSource = filenamesList }


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5567220.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-14
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存