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.

Error in Grid Data bound grid

Thread ID:

Created:

Updated:

Platform:

Replies:

56840 Feb 21,2007 11:20 AM Feb 21,2007 01:03 PM Windows Forms 2
loading
Tags: GridControl
Adnan Sohail
Asked On February 21, 2007 11:20 AM

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;

Adnan Sohail
Replied On February 21, 2007 11:24 AM

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?

Administrator [Syncfusion]
Replied On February 21, 2007 01:03 PM

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.

CONFIRMATION

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.

;