Hello,In my windows application , I am loading a form having datagridview. First i bind this datagrid to database than i try to change particular link cell based on certain condition.

 int key = 0,CountCheck;
            string CheckSql;
                foreach (DataGridViewRow dgr in dataGridView1.Rows)
                    key = Convert.ToInt32(dgr.Cells["id"].Value);
                    CheckSql = "Select count(catg_id) as Id From tbl_master Where deleted='n' and catg_id=" + key;
                    CountCheck= objCon.ExecuteScalar(CheckSql);

                    if (CountCheck > 0)

                        DataGridViewTextBoxCell TxtCell = new DataGridViewTextBoxCell();
                        TxtCell.Style.BackColor = Color.LimeGreen;
                        dgr.Cells["del"] = TxtCell;
                    CountCheck = 0;
            catch (Exception ex)

This Code Works when i write the same on click event of a button but not on form load event. Trying to Figure Out Why This is being happen. ( In my code i want to disable delete link if condition met )

Hi dd2308, What do you mean by the code doesn't work when you put it in the form load event, does it give you an error?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.