开发者

First Column not hiding in datagridview

开发者 https://www.devze.com 2022-12-21 14:15 出处:网络
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

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 s开发者_Go百科omereason this gridview is acting different. I am going to try an rearrange the columns and see if that helps.


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.


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


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)
0

精彩评论

暂无评论...
验证码 换一张
取 消