使用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 }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)