Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DataGrid Behaviour
Message
De
14/11/2007 12:35:19
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Titre:
DataGrid Behaviour
Divers
Thread ID:
01268926
Message ID:
01268926
Vues:
51
Hello,

I got this problem with a c# DataGridView in VS2005:

The DataGridView has 2 columns: colArtigoGenerico, colArtigoFinal; and this columns are populated with data from 2 columns from a DataTable: "Detalhes".

1st i populate the DataGrid with a Datatable using this code:
string select = "SELECT a.CArtigoGenerico, a.CArtigoFinal " +
"FROM ArtigosGenericos a ORDER BY a.CArtigoGenerico ";
SqlDataAdapter adaptador = new SqlDataAdapter(select, ligacao);
adaptador.Fill(Detalhe, "Detalhes");

// Populate the Grid:
DGV.AutoGenerateColumns = false;
DGV.DataSource = Detalhe.Tables["Detalhes"];

DGV.Columns["colArtigoGenerico"].DataPropertyName = "CArtigoGenerico";
DGV.Columns["colArtigoFinal"].DataPropertyName = "CArtigoFinal";

ColArtigoGenerico.ValueMember = DGV.Columns[0].DataPropertyName;
ColArtigoFinal.ValueMember = DGV.Columns[1].DataPropertyName;
The above code is in a button_click event. And the 1st time i run it, the grid is populated correctly.
Then i set the DataSource to null and the DataGridView, as expected, collapses and shows no record.

Then i click again in the 1st button, and the DataGridView, this time, shows no record.

In a debug session i see that the DataTable has some records, and after the code line:
DGV.DataSource = Detalhe.Tables["Detalhes"];
The DGV.RowCount property returns 0, that's why it shows no record in the Grid.

But the DataTable that is the DataSource for the Grid has 3 records.

Why does the DataGrid behaves like it should at the first time and not in the 2nd and following times if it runs the same code?

TIA,
Joaquim
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform