Home - Forums-.NET - FlyGrid.Net (Windows Forms) - issue binding a LookupListColumn to a non standard data sour

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

issue binding a LookupListColumn to a non standard data sour
Link Posted: 12-Jul-2006 08:39
Hi,

I have an object that implements IBindingList, ITypedList and IListSource.  It has been bound to all sorts of other controls, and no issues so far. The code is too large to post here, and too dependent on the specifics of the system.

In any case, I am trying to use it as the datasource for a LookupListColumn.

The list of items displays correctly. So it is able to read the object, figure out how many rows it has, gets the value of the appropriate column, etc.

However, even if the grid cell's value is a value in whatever column LookupBoundField is set to, the cell always displays the first item in the list.

Example, if i have the numbers 1-10 in the list, and my grid is getting populated with values 1 through 10 in that column, the only value that ever display is 1.

It looks like the grid isn't able to map the value from the cell to the correct item in the dropdown's source, so it gives up and shows the first item.

If I select an item from the dropdown (which looks correct), nothing happens, the value remains at one.

What could the problem be? Everything is a string in this case.

The other question this brings up, is that this would imply that even if the cell had no value, the first item in the dropdown would be defaulted in. This seems sort of odd.  If in reality that cell has no value - shouldn't it display as empty?
Link Posted: 12-Jul-2006 09:05
It looks like the grid isn't able to map the value from the cell to the correct item in the dropdown's source, so it gives up and shows the first item.

May be you forget to define LookupListColumn.LookupDisplayField?
[c#]
// The Datatable has following data structure:
// FieldName: LandId (Type: int) //unique id of country
// FieldName: LandName (Type: string) //name of the country
// Datatable has following field values:
// LandId    | LandName    
// ------------------------
// 1         | USA
// 2         | UK
// 3         | Canada
// 4         | France
// 5         | Germany

private void InitFlyGrid(FlyGrid flyGrid, DataSet ds)
{
  flyGrid.BeginInit();
  try
  {
    //....initialization code here
    //Get a countries dictionary table
    DataTable countries = ds[\"Countries\"];
    AddLookupColumnForDatatable(countries, \"Country\", \"LandId\", \"LandName\");
  }
  finally
  {
    flyGrid.EndInit();
  }
}
private void AddLookupColumnForDatatable(DataTable data, string fieldName, string lookupFieldName, string lookupDisplayFieldName)
{
  LookupListColumn lookupCol = new LookupListColumn(\"fieldName\");
  lookupCol.LookupBoundField = lookupFieldName;
  lookupCol.LookupDisplayField = lookupDisplayFieldName;
  lookupCol.LookupSource = data;
}