First Column not hiding in datagridview

こ雲淡風輕ζ 提交于 2020-01-04 06:45:11

问题


I have a datagridview and once I populate the view with the data source I hide the columns that I do not need. For some reason the 1st column is not hiding. I have checked the column name and they match and the 2nd line executes fine hides the column for the EVENTID. I even did a messagebox.show( dgvTourOther.Columns("OTHERID").name) and it returned the correct name.

dgvTourOther.Columns("OTHERID").Visible = False
dgvTourOther.Columns("EVENTID").Visible = False

Any idea what could cause a datagridview not to hide a column? It is like some other property is locking that column..

The values being passed are all strings. I do this on 3 other datagridviews ok but for somereason this gridview is acting different. I am going to try an rearrange the columns and see if that helps.


回答1:


I remember having this issue on a project a couple years ago. There were two potential solutions as I recall. The first was moving the .Visible setting code out of the Constructor (assuming thats where you have it now) and into something like the Form_Load event.

The second solution (which may have been what really worked for me) was to move the columns I wanted to hide to the end (right side) of the grid. Stupid I know.




回答2:


Are the name of the column in datagridview same as that which are in the datasource. This can be a reason for this problem




回答3:


This happens when we clear the Datagridview columns and setting the columns property. In that case set DGV source after you defined the columns property.

            dgvProdGrp.DataSource = Nothing
    With dgvProdGrp.Columns
        .Clear()
        .Add(clsCommon.setTextColumn("prdg_id", "prdg_id", 0, 0, True, DataGridViewContentAlignment.MiddleLeft, ""))
        .Add(clsCommon.setTextColumn("prdg_name", "Group Name", 200, 1, True, DataGridViewContentAlignment.MiddleLeft, ""))
    End With
    dgvProdGrp.DataSource = objDB.View_ProdGrp(1)


来源:https://stackoverflow.com/questions/2342107/first-column-not-hiding-in-datagridview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!