我有一个带有两个公共属性的类,即Name和Text。我想将DataGridView绑定到这些对象的列表,所以我将它们加载到BindingList 中。我只想在DataGridView中显示Name属性,但是我同时获得了两列。我究竟做错了什么?private void fileOpenTextBox1_FileSelected(object sender, string e){ m_definitions = new BindingList<TagSimDefinition>(TagSimDefinition.Read(e)); dgvTagNames.AutoGenerateColumns = false; dgvTagNames.Columns.Clear(); DataGridViewCell cell = new DataGridViewTextBoxCell(); DataGridViewTextBoxColumn colTagName = new DataGridViewTextBoxColumn() { CellTemplate = cell, Name = "colTagName", HeaderText = "Tag Name", DataPropertyName = "Name" }; dgvTagNames.Columns.Add(colTagName); dgvTagNames.DataSource = m_definitions;} (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 @罗伯特,你正在设置,dgvTagNames.DataSource = m_definitions;为此,它显示了两列。如果您想获得一栏,请像这样使用它,m_definitions = new BindingList<TagSimDefinition>(TagSimDefinition.Read(e));dgvTagNames.AutoGenerateColumns = false;dgvTagNames.Columns.Clear();dgvTagNames.ColumnCount = 1;dgvTagNames.Columns[0].Name = "colTagName";dgvTagNames.Columns[0].DataPropertyName = "colTagName";dgvTagNames.DataSource = m_definitions;另一个解决方案: m_definitions = new BindingList<TagSimDefinition>(TagSimDefinition.Read(e)); dgvTagNames.Columns.Clear(); DataGridViewCell cell = new DataGridViewTextBoxCell(); DataGridViewTextBoxColumn colTagName = new DataGridViewTextBoxColumn() { CellTemplate = cell, Name = "colTagName", HeaderText = "Tag Name", DataPropertyName = "Name" };dgvTagNames.Columns.Add(colTagName);dgvRegion.Rows.Clear();int index = 0;foreach (var dparam in m_definitions){ dgvTagNames.Rows.Add(); dgvTagNames["colTagName", index].Value = dparam.<Property1>; dgvTagNames.Rows[index].Tag = dparam; index++;}关于c# - 绑定(bind)到BindingList的DataGridView显示太多列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36319610/ (adsbygoogle = window.adsbygoogle || []).push({}); 10-09 19:19