How can I check if a DataGridView contains column “x” and column “x” is visible?

前端 未结 5 1487
耶瑟儿~
耶瑟儿~ 2021-01-11 10:13

How can I check if a DataGridView contains column \"x\" and column \"x\" is visible?

All I have so far is below.

if (Dgv.Columns.Contain         


        
5条回答
  •  盖世英雄少女心
    2021-01-11 10:45

    Firstly verify if the column exists and then you verify its visibility.

    Calling the column's property for a column that does not exist will crash.

    if (dgv.Columns.Contains("Address")
    {
        if ( dgv.Columns["Address"].Visible )
        {
    
        }
    }
    

提交回复
热议问题