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.
Unfortunately, activation email could not send to your email. Please try again.

Databinding, with no items not working

Thread ID:





9194 Dec 10,2003 01:32 AM May 5,2004 09:06 AM Windows Forms 5
Tags: GridControl
Asked On December 10, 2003 01:32 AM

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é

Administrator [Syncfusion]
Replied On December 10, 2003 02:32 AM

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();

Replied On December 10, 2003 02:57 AM

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é

Administrator [Syncfusion]
Replied On December 10, 2003 05:37 AM

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.....

Administrator [Syncfusion]
Replied On December 10, 2003 06:52 AM

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.

Administrator [Syncfusion]
Replied On May 5, 2004 09:06 AM

Thank you Clay!!!


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.