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

Error in Grid Data bound grid

Hi,

I am trying to run this code and it produces an error i.e. the index is out of range. In immediate window, when i look at this.gridDatabound1.GridBoundColumns.Count, it shows it as 0. According to my understanding this grid should have 4 bound columns. Here is the snippet:

DataTable myDataTable = new DataTable("MyDataTable");

myDataTable.Columns.Add("ID");
myDataTable.Columns.Add("Name");
myDataTable.Columns.Add("Address");
myDataTable.Columns.Add("City");

DataRow[] row = new DataRow[10];

for (int i = 0; i < 10; i++)
{
row[i] = myDataTable.NewRow();
row[i]["ID"] = i + 1;
row[i]["Name"] = "Ali Sohail";
row[i]["Address"] = "Granton Cove";
row[i]["City"] = "Manor";

myDataTable.Rows.Add(row[i]);
}


// Setting up datasource
this.gridDataBoundGrid1.DataSource = myDataTable;

// Sizing columns
this.gridDataBoundGrid1.Model.ColWidths[1] = 100;
this.gridDataBoundGrid1.Model.ColWidths[2] = 100;
this.gridDataBoundGrid1.Model.ColWidths[3] = 100;
this.gridDataBoundGrid1.Model.ColWidths[4] = 100;

// Create the list.

StringCollection items = new StringCollection();

items.AddRange(new string[]{"One", "Two", "Three", "Four", "Five"});

// Set the style properties.

GridStyleInfo style = this.gridDataBoundGrid1.GridBoundColumns[2].StyleInfo;

style.CellType = "ComboBox";

style.ChoiceList = items;

style.CellValue = "Five";

// True droplist - no editing.

style.DropDownStyle = GridDropDownStyle.Exclusive;

2 Replies

AS Adnan Sohail February 21, 2007 04:24 PM UTC

ok .. i figured out that i just need to change gridboundcolumns to binder.internalcolumns.

Will it recognize gridboundcolumn if i set the datasource at design time?


AD Administrator Syncfusion Team February 21, 2007 06:03 PM UTC

No, just setting the datasource at design time will not populate the grid.GridBoundColumns collection. Unless you explicitly add GridBoundColumns to the grid.gridBoundColumns collection, the grid will use the grid.Binder.InternalColumns collection. But you can explicitly add GridBoundColumns either at design time, or at runtime.

Loader.
Live Chat Icon For mobile
Up arrow icon