You must Sign In to post a response.
  • Category: Windows

    Show image instead of checkbox in DataGridView

    Hi,

    I tried lot for this type of coding but with no success. So I need you all DNSian help.

    Problem:
    -----------
    You have been given the assignment of retrieving values from database and displaying those values in DataGridView. One of the column in database contains boolean type values (true/false). Now you need to show image in place of those values in DataGridView.

    Thanks and Regards,
    Vikram Singh Saini
  • #532944
    You want images for True/False values ?

    Like When the value is True image should show T or TRUE

    if its value is False image should show either F or FALSE

    is this right ?

    Thanks
    Shekar.Y

  • #532966
    Hello @Chandra Shekar.Y,

    What are you saying is correct except that when value is true I am having custom image to show. And so the custom image would be displayed to the user.
    Regards,
    Vikram Singh Saini

    RESULTS MATTER, REASONS NOT!

  • #533056
    take template field.

    on edit template take checkbox and image.

    now visible=false int the checkbox property

    now you can use image.

    Regards:
    Pal(Parthiv) Patel

    If you Like My Post Then Please Go to Below link and Like this facebook page.

  • #533073
    windows application use DataBindingComplete event to set the image

    Place image in column , if it true set visible false else visible true


    void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
    {
    for (int i = 0; i < dataGridView1.Rows.Count; i++)
    {
    Boolean b=Convert.ToBoolean(dgv_Airport.Rows[i].Cells[3].Value.ToString());

    DataGridViewImagebutton comboCell = (DataGridViewImagebutton )dataGridView1.Rows[i].Cells["imgbtn"];

    if (b)
    {
    combocell.visible=true;
    }
    else
    {
    combocell.visible=false
    }
    }
    }

    Please check DataGridViewImagebutton avaiable in windows application else change based on your image type column

    hope this help!

    thnx
    Muhil

  • #533374

    private void Form1_Load(object sender, EventArgs e)
    {
    dataGridView1.AutoGenerateColumns = true;
    DataSet set = new DataSet("Employee");
    set.ReadXml("../../Resources/Employee.xml");
    dataGridView1.DataSource = set.Tables[0];
    DataGridViewImageColumn imageColumn = new DataGridViewImageColumn(false);
    imageColumn.Name = "Image";
    dataGridView1.Columns.Add(imageColumn);
    BindTheImageColumn();
    }




    private void BindTheImageColumn()
    {
    foreach (DataGridViewRow row in dataGridView1.Rows)
    {
    DataRowView view = row.DataBoundItem as DataRowView;
    if (view != null)
    {
    if (Convert.ToString(view.Row["IsExist"]) == "1")
    {
    row.Cells["Image"].Value = Image.FromFile("../../Resources/true.jpg");
    }
    else
    {
    row.Cells["Image"].Value = Image.FromFile("../../Resources/false.jpg");
    }
    }
    }
    }

    Thanks
    Shekar.Y

  • #534287
    Hi,

    Thanks to all of you for your solutions. But now I have implemented the same my own.

    I will assign rating to your each solution accordingly.

    If any of you want to check you can visit link:
    http://niitdeveloper.blogspot.com

    Regards,
    Vikram

    RESULTS MATTER, REASONS NOT!


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.