Windows Develop Bookmark and Share   
 index > Windows Forms Designer > BindingList with Images?
 

BindingList with Images?

I have a DataGridView on my form with the following columns defined:
Download (type DataGridViewCheckBoxColumn)
ImageName (type DataGridViewLinkColumn)
Thumbnail (type DataGridViewImageColumn)
NITFFile (type DataGridViewLinkColumn);

My question is how do I create a BindingList to populate the DataGridView properly?

I tried the following class for my BindingList but it doesn't work. The only thing that shows up correctly in my DataGridView is the checkbox.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public class ImageDataSet
{
    public ImageDataSet(CheckBox cb, string image_name, Image thumbnail, string nitf_image)
    {
            _myCB = cb;
            _myImageName = image_name;
            _myThumbnail = thumbnail;
            _myNITFName = nitf_image;
    }
    private CheckBox _myCB;
    public CheckBox MyCB
    {
            get { return _myCB; }
            set { _myCB = value; }
    }
    private string _myImageName;
    public string MyImageName
    {
            get { return _myImageName; }
            set { _myImageName = value; }
    }
    private Image _myThumbnail;
    public Image MyThumbnail
    {
            get { return _myThumbnail; }
            set { _myThumbnail = value; }
    }
    private string _myNITFName;
    public string MyNITFName
    {
            get { return _myNITFName; }
            set { _myNITFName = value; }
    }
}



//////////////////////////////////////////////////////////////////////////////////////////////

This is how I try to add something to the BindingList:
//////////////////////////////////////////////////////////////////////////////////////////////

myList.Add(new ImageDataSet(
                            new System.Windows.Forms.CheckBox(), 
                            image_file, 
                            Image.FromFile(imagefilename),
                            "Coming Soon"));



////////////////////////////////////////////////////////////////////////////////////////////


Any ideas on what I am doing wrong? (this is my first time working with BindingLists)

Thanks in advance!!!!

-Andrew

  • Moved byHarry ZhuMSFTMonday, August 03, 2009 6:04 AMrelating to bingdinglist (From:Visual C# General)
  • Edited byAndrew_Tree Thursday, July 30, 2009 7:18 PM
  •  
Andrew_Tree  Thursday, July 30, 2009 6:58 PM
I don't know, but put your code with the Insert Code Block gizmo and specify that it is C# code and it will be easier to read.

    public string MyNITFName
    {
            get { return _myNITFName; }
            set { _myNITFName = value; }
    }

GOBS13  Thursday, July 30, 2009 7:10 PM

I have a DataGridView on my form with the following columns defined:
Download (type DataGridViewCheckBoxColumn)
ImageName (type DataGridViewLinkColumn)
Thumbnail (type DataGridViewImageColumn)
NITFFile (type DataGridViewLinkColumn);

My question is how do I create a BindingList to populate the DataGridView properly?

I tried the following class (C# code)for my BindingList but it doesn't work. The only thing that shows up correctly in my DataGridView is the checkbox.

public class ImageDataSet
{
    public ImageDataSet(CheckBox cb, string image_name, Image thumbnail, string nitf_image)
    {
            _myCB = cb;
            _myImageName = image_name;
            _myThumbnail = thumbnail;
            _myNITFName = nitf_image;
    }

    private CheckBox _myCB;
    public CheckBox MyCB
    {
            get { return _myCB; }
            set { _myCB = value; }
    }

    private string _myImageName;
    public string MyImageName
    {
            get { return _myImageName; }
            set { _myImageName = value; }
    }

    private Image _myThumbnail;
    public Image MyThumbnail
    {
            get { return _myThumbnail; }
            set { _myThumbnail = value; }
    }

    private string _myNITFName;
    public string MyNITFName
    {
            get { return _myNITFName; }
            set { _myNITFName = value; }
    }
}




This is how I try to add something to the BindingList:

myList.Add(new ImageDataSet(
                            new System.Windows.Forms.CheckBox(), 
                            image_file, 
                            Image.FromFile(imagefilename),
                            "Coming Soon"));




Any ideas on what I am doing wrong? (this is my first time working with BindingLists)

Thanks in advance!!!!

-Andrew

  •  
Andrew_Tree  Thursday, July 30, 2009 7:15 PM
Your code does not create a binding list. Binding lists implement the IBindingList interface. Also for it to be a "list", it has to have more than one object. You are just passing one object.

I don't understand why you need to create an entire CheckBox control when a simple boolean suffice to correctly populate a DataGridViewCheckBoxColumn. The DataGridView is smart enough to create its own checkbox, you know? You don't have to provide one.

If you want to create your own binding list, derive a new class from BindingList<>, or create a class that implements IBindingList.

Binding lists are basically IList objects with change notification services and a few other things useful for data binding. However, note that you can bind to any IList, including a simple array.
MCP
  • Proposed As Answer bywebJose Wednesday, September 23, 2009 4:56 AM
  •  
webJose  Friday, September 04, 2009 4:21 PM

You can use google to search for other answers

Custom Search

More Threads

• issue : Grid Scrollbar maintain scroll bar position after refresh Grid
• Is there container or controls mangering the process running
• Doing undo & redo operations....
• Hi ! Please Help on Combo Box as soon as possible.
• Control Layout problem
• Visual Studio 2005 Reinstallation Critical problem
• calender control
• Extensibility DTE Object Unavailable (error) in WinForms Design
• How to host a WebControl in my custom designer
• WinForms designer throws Exception when adding fillToolStrip component from DataSet without TableAdapters