DataGridView button column image depends on the value

183 Views Asked by At

I have a button column in my grid that can have 0-1 integer value and it will show up(1) or down(0) image depends on the value. Also with the click event i want to toggle this value with image.

            btnClmnA1.HeaderText = "";
            btnClmnA1.Name = "A1";
            btnClmnA1.Width = 50;
            btnClmnA1.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgvUser.Columns.Add(btnClmnA1);

That was my approach but i couldn't handle with it.

private void dgvUser_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
    {
        if (dgvUser.Columns[e.ColumnIndex].Name == "A1")
        {
            if (e.Value.ToString() == "1")
            {
                //image will be up
            }
            else if(e.Value.ToString() == "0")
            {
                //image will be down
            }
        }
    }

Any help will be appreciated.

0

There are 0 best solutions below