Same code but different result..........?
Same code but different result..........?
Variable (C#: row / PHP: $row) is derived from DataTable NewRow(), which data are added to it successfully but in the real C# it data display well in DataGridView but in Phalanger the DataGridView shows only the text 'System:::Data:::DataRow' in the first column of each row, the code of the 2 languages are below.
Is this a bug or I am still getting something wrong?
table.Rows.Add(row); //This is working well.
$table->Rows->Add($row); // dont work well
//Pure C# ***********************************************
private void MakeDataTableAndDisplay()
{
// Create new DataTable and DataSource objects.
DataTable table = new DataTable();
// Declare DataColumn and DataRow variables.
DataColumn column;
DataRow row;
DataView view;
// Create new DataColumn, set DataType, ColumnName and add to DataTable.
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "id";
table.Columns.Add(column);
// Create second column.
column = new DataColumn();
column.DataType = Type.GetType("System.String");
column.ColumnName = "item";
table.Columns.Add(column);
// Create new DataRow objects and add to DataTable.
for(int i = 0; i < 10; i++)
{
row = table.NewRow();
row["id"] = i;
row["item"] = "item " + i.ToString();
table.Rows.Add(row);
}
// Create a DataView using the DataTable.
view = new DataView(table);
// Set a DataGrid control's DataSource to the DataView.
dataGrid1.DataSource = view;
}
//Phalanger PHP *****************************************
private function button1_Click(System:::Object $sender, System:::EventArgs $e) {
// Create new DataTable and DataSource objects.
$table = new DataTable();
// Create new DataColumn, set DataType, ColumnName and add to DataTable.
$column = new DataColumn();
$column->DataType = System:::Type::GetType("System.String");
$column->ColumnName = "id";
$table->Columns->Add($column);
// Create second column.
$column = new DataColumn();
$column->DataType = System:::Type::GetType("System.String");
$column->ColumnName = "item";
$table->Columns->Add($column);
// Create new DataRow objects and add to DataTable.
for ($i = 0; $i < 10; $i++)
{
$row = $table->NewRow();
$row["id"] = $i;
$row["item"] = "item " . $i;
$table->Rows->Add($row);
}
// Create a DataView using the DataTable.
$view = new DataView($table);
// Set a DataGrid control's DataSource to the DataView.
$this->dataGridView1->DataSource = $view;
}
- kielsoft
- Posts: 25
- Joined: March 1st, 2012, 3:39 pm
Who is online
Users browsing this forum: No registered users and 7 guests