0

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.

CanESER
  • 301
  • 1
  • 3
  • 19
  • For `DataGridView` you need to create your own "DataGridViewImageButtonColumn". Standard `DataGridViewButtonColumn` don't support images – Fabio Jun 07 '16 at 08:41
  • Possible duplicate of [DataGridView Image Button Column](http://stackoverflow.com/questions/6645699/datagridview-image-button-column) – Fabio Jun 07 '16 at 08:43
  • That example is just an image button, my buttons need different images depends on its value. @Fabio – CanESER Jun 07 '16 at 08:51
  • When you get image there you get example how to change image in `CellClick` event – Fabio Jun 07 '16 at 08:54
  • Maybe I should try image column instead of button cos i can handle about image with it but how can i make it seem like button? @Fabio – CanESER Jun 07 '16 at 09:00
  • If it is new project, then move to WPF where you have free hands to play with user interface. Other way deal with `ImageColumn`, just accept it not looking as button, or create your own custom `ImageButtonColumn`, or use some third party library (Telerik, DevExpress or some else) – Fabio Jun 07 '16 at 09:06
  • Unfortunately its not new project, and i cant use third party libraries cos of its commercial project. I will try to find another way. Thanks for ur help @Fabio – CanESER Jun 07 '16 at 09:14

0 Answers0