DataGridView automatically generates columns

前端 未结 5 2019
没有蜡笔的小新
没有蜡笔的小新 2021-01-17 14:57

On my Windows Form I have a DataGridView component, which is bound to a BindingSource. The BindingSource is an object datasource to an EntityFramework object.

Some t

相关标签:
5条回答
  • 2021-01-17 15:31

    I actually don't know when this happens, but I tend to create all the columns manually. I create the columns in the designer and set the AutoGenerateColumns property to false in my code.

    0 讨论(0)
  • 2021-01-17 15:44

    I had the same problem. I couldn't find the AutoGenerate property in my code.

    For reasons I do not understand my DataGridView does not have an AutoGenerate property that I can see in my VB code.

    I do not see a checkbox on the Edit Columns dialog box.

    I do not see an AutoGenerate property in the grid's properties view.

    I have Visual Studio Community 2017.

    Here's my class properties:

    Public Property BatchId As Integer
    Public Property Code as String
    Public Property Count As Integer
    Public Property Description As String
    Public Property Id As Integer

    So, here's what I did:

    1. I went to the form designer.
    2. I right-clicked on the DataGridView.
    3. I selected Edit Columns.
    4. I made sure each column had the DataPropertyName field set to the class property name.

    When I ran my application the DataGridView displayed only those columns in my class.

    0 讨论(0)
  • 2021-01-17 15:49

    Set AutoGenerateColumns property to False but keep remember do it just before databinding. eg: DataGridView1.AutoGenerateColumns=false; DataGridView1.DataSource=getData();

    By default it is set to True.

    0 讨论(0)
  • 2021-01-17 15:50

    Try leave first of auto generated columns and set it visibility false. If it don't help try leave all them with Visible=false. Sorry for bad English.

    0 讨论(0)
  • 2021-01-17 15:57

    Add this code or change your DataGridView Property AutoGenerateColumns to false

    DataGridView1.AutoGenerateColumns=false;
    
    0 讨论(0)
提交回复
热议问题