DataGridView without selected row at the beginning

后端 未结 12 1099
栀梦
栀梦 2021-02-12 14:23

In my WinForms I have DataGridView. I wanted to select full row at once so I set SelectionMode as FullRowSelect. And now I have problem, b

12条回答
  •  南旧
    南旧 (楼主)
    2021-02-12 14:44

    If this is because it raised unwanted GridView1_SelectionChanged event on initial loading, you can use a flag to handle this

    public partial class YourFormName
    { 
        private bool IsReady= false;
    
        private void YourFormName_Load(object sender, EventArgs e)
        { 
               //Load your GridView1...
               //Format your GridView1...
                IsReady = true;
        }
        void GridView1_SelectionChanged(object sender, EventArgs e)
        {
             if (!IsReady) 
                 return;
             //do the rest of the stuffs
        }
    }
    

提交回复
热议问题