We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Databinding, with no items not working

Hey, I am evaluating the grid component, and I am having trouble getting the binding to work. I have a collection/arraylist with some type of object, when I set the datasouce AFTER I have populated the arraylist with some objects, the grid works fine, and can show the values from my objects, but if I set the datasource before I have added any objects to to list, I cant get it to show the values in the grid. If I refresh the grid, I can get it to show rows according to the number of items in the arraylist, but its not using the values. Is there a way to refresh/reinitiate the grid so it knows how the objects mappingnames are after its been bound? I have addede the colums to the gridboundcollums collection. /René

5 Replies

AD Administrator Syncfusion Team December 10, 2003 07:32 AM UTC

If your DataSource implements IBindingList, then you should not have to do anything to get a non-hierarchical GridDataBoundGrid to show new data. But if your data source does not support IBindingList (and hence does not fire the appropriate updating events), you will have to do more work to get the GridDataBoundGrid to show the new data. If you are changing existing values, then you can call grid.RefreshRange passing in the range in the grid that you have changed. this.gridDataBoundGrid1.RefreshRange(GridRangeInfo.Cell(rowIndex, colIndex), true); If you are adding/removing an item in your collection, then you would have to call grid.Refresh() to get things synced up. this.gridDataBoundGrid1.Refresh();

RE René December 10, 2003 07:57 AM UTC

Hey Clay, the problem is that there are no items in the arraylist, when setting the datasource, - if I put just one item in the arraylist before setting it to the datasource, then I have no problem, but I need to be able to bind a clean list to the grid, and afterwards add items programmaticly. Also when trying to bind without any columns in the gridboundcolumns, then the grid wont automaticly create them from the objects properties, but if there is items in the list it will. So is there a method to call to do the updating as when the datasource is bound? or what do I do. /René

AD Administrator Syncfusion Team December 10, 2003 10:37 AM UTC

In order to get things to work with an empty arraylist, you have to do two things. 1) Have your arraylist strongly typed by implementing ITypedList. 2) Make sure your derived object class (USState in the code below) has a default contructor. In order to create the appropriate columns, the grid has to be able to get the information on the properties of the objects in your arraylist. The above steps facilitate this.
public class USArrayList : ArrayList, ITypedList
	public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
		return TypeDescriptor.GetProperties(typeof(USState));
	public string GetListName(PropertyDescriptor[] listAccessors)
		return "USStatesList";

public class USState
	private string myShortName ;
	private string myLongName ;
	private int _imageIndex;

	public  USState() //default constructor
		this.myShortName = "";//"defaultShortName";
		this.myLongName = "";//"defaultLongName";
		this._imageIndex = -1;

// other code.....

AD Administrator Syncfusion Team December 10, 2003 11:52 AM UTC

In the previous post, I said you had to do the two things (ITypedList and default constructor) to get things to work. That was not correct. If you implement ITypedList, you do not have to have a default contructor. Implementing the ITypedList interface is sufficient. On the other hand, if you have only a strongly typed ArrayList (handles the ''this'' property and the Add method to manage the type) which does not implement ITypedList, then you do need the default contructor for the typed object.

AD Administrator Syncfusion Team May 5, 2004 01:06 PM UTC

Thank you Clay!!!

Live Chat Icon For mobile
Up arrow icon