Reputation: 1438
I have a DataGridView
that I bind on a BindingSource
.
The thing is, when I do a filter on it, it doesn't work.
Is it needed, to add Filter
on a BndingSource DataSource
, that the DataSource
is a DataTable
.
For now, it is jst a list of Object, but I can return a DataTable
.
Should I change it or not?
bindingSource1.DataSource = Echange.GetListEchange(contextExecution.ChaineConnexion, criteres);
GetListEchange, return a list of Echange.
But with this, the filter doesn't work :
bindingSource1.Filter = "ec.date_echange IS NULL";
So, this will work if I return a DataTable
instead?
Hope I can use Filter
without returning a DataTable
but, if I have to do it, no problem.
Generate the DataTable :
vRequete += vFrom + " " + vWhere.Trim().TrimEnd("AND".ToCharArray()) + " " + vOrderBy;
vTable = vTarget.RenvoiOneTable(vRequete);
RenvoieOneTable is a method providing by Oracle. The code is :
public override DataTable RenvoiOneTable(string piRequest)
{
DataTable poDatable = null;
try
{
poDatable = ChargeDataSet(piRequest).Tables[0];
}
catch (OracleException ThisException)
{
throw new BaseDonneesException(ThisException.Message);
}
catch (Exception ThisExcept)
{
throw new BaseDonneesException(ThisExcept.Message);
}
return poDatable;
}
public override DataSet ChargeDataSet(string piRequest)
{
DataSet poDataset = null;
try
{
//Ouverture de la connection
Connexion.Open();
//Initialisation de la commande
Command.CommandType = CommandType.Text;
//Mise en place dans la variable po_datasets de l'identifiant et du
//dataset voulu
Command.CommandText = piRequest;
using (OracleDataAdapter vAdapter = new OracleDataAdapter(Command))
{
poDataset = new DataSet();
vAdapter.Fill(poDataset);
}
}
catch (OracleException ThisException)
{
throw new BaseDonneesException(ThisException.Message);
}
catch (Exception ThisExcept)
{
throw new BaseDonneesException(ThisExcept.Message);
}
finally
{
if (Connexion.State == ConnectionState.Open)
{
Connexion.Close();
}
}
//Envoye du tableau de DataSet
return poDataset;
}
Thank you.
Upvotes: 0
Views: 697
Reputation:
A DataGridView
can only deal with one set of 2D information (i.e., one DataTable
). Although it is not bad to rely on a Binding
variable (actually, it is recommended by MSDN), the reality is that the DataGridView only relates to one of its DataTables (in case of having more than one in the binding source, you would have to specify the one you want to be the DataSource
via the DataMember
property).
Thus, any change you want to do in the DataSource has to be done in the given DataTable, in case of considering a binding source; and thus the behaviour you are observing is the expected one.
Upvotes: 1