Posted 30 June 2021, 5:55 pm EST
Hello there!!!
Im under development and Im using FlexGrid, on previous views I used an observable collection as datasource for my grid, that works fine since the data are using a fixed number of columns.
I have this new problem, on the same view I have to display different data depending on the button the user selects… So… on 1st button I display 4 columns, on the 2nd 6 cols and so with other 5 buttons.
To work around my problem (because of time) I declared 7 different types of data depending on the kind of data I need to be displayed. But it become so “ugly to read” on code.
I tried instead binding a recordset, a datable, an empty list<> or a collection<> that fills up depending on the data I read from the database.
Is there a way to display data on the FlexGrid using a System.Data.DataTable or a System.Data.SQLClient.SqlDataReader that I can “assign” directly as ItemSource and it displays the correct number of columns according to the data itself??
This is part of my code where I create the “fixed” collection (yuck…) and use it as source for the FlexGrid
SqlDataReader objRegistros = null;
clsRespuesta Respuesta = VariablesGenerales.objConexion.Consultar(sSQLQuery, ref objRegistros);
if (Respuesta.ResultadoCorrecto)
{
//SE TOMAN ALGUNOS DATOS DEL REGISTRO PARA CONFIGURAR CORRECTAMENTE EL GRID DINAMICO
int iColumnas = 0;
while (objRegistros.Read())
{
Columnas_PROD_MapeoInterno RegistroNuevo = new Columnas_PROD_MapeoInterno(objRegistros);
PROD_MapeoInterno.Add(RegistroNuevo);
}
iColumnas = objRegistros.FieldCount;
objRegistros.Close();
VariablesGenerales.objConexion.Desconectar();
GrdDetalle.ItemsSource = PROD_MapeoInterno;
GrdDetalle.AutoSizeMode = C1.iOS.Grid.GridAutoSizeMode.None;
Im also sharing my “file” if you can use it as reference for the question…
What I’d like to do is directly something like this…:
GrdDetalle.ItemsSource = objRegistros; //where objRegistros is a SQLDataReader or can be a DataSet