Hello good day, to make my application using Telerik controls.
I have problems when displaying records in my datagridview.
If my first query returns 1 record, then my datagridview displays 1 row.
I immediately made another query that returns me 3 records, but my datagridview displays only 1 row.
The problem is I can only display the first number of rows obtained by my query to the database, no more than that.
This is the code I use to link data table.
METHOD PRIVATE VOID EnlazaTabla():
DEFINE VARIABLE httRegistro AS HANDLE NO-UNDO. DEFINE VARIABLE hDataSet AS HANDLE NO-UNDO. DEFINE VARIABLE hBuffttRegistro AS HANDLE NO-UNDO. DEFINE VARIABLE hRegistroQry AS HANDLE NO-UNDO. hDataSet = DATASET dsRegistro:HANDLE. httRegistro = TEMP-TABLE ttRegistro:HANDLE. hBuffttRegistro = httRegistro:DEFAULT-BUFFER-HANDLE. DEFINE DATA-SOURCE fuenteDatos FOR ttMedicionesSucursal. hBuffttRegistro:ATTACH-DATA-SOURCE(DATA-SOURCE fuenteDatos:HANDLE,?,?,?). hRegistroQry = hDataSet:TOP-NAV-QUERY(). hDataSet:FILL(). listaMediciones:DataSource = ?. listaMediciones:Update(). listaMediciones:Refresh(). bindingSource1 = ?. bindingSource1 = NEW Progress.Data.BindingSource(DATASET dsRegistro:HANDLE, "ttRegistro.Sucursal,ttRegistro.Fecha,ttRegistro.Medida, ttRegistro.Medicion, ttRegistro.HoraCaptura", ""). listaMediciones:DataSource = bindingSource1. listaMediciones:TabIndex = 1. END METHOD.
First you should not be detaching the grid from the data source and then reattaching it. A lot goes on behind the scenes when you do that, that you don't want to be happening. And you shouldn't need that update and refresh of the grid either, not the creation of a new BindingSource.
In order to see the new set of records in the Grid, you need to reopen the query so that the new set of rows is in the result set. That should do it. If not, you can call RefreshAll() on the BindingSource which broadcasts to the grid to re display. But using the default BindingSource settings you shouldn't need that.
So, you only need to make the BindingSource once, attach it once, and then reopen the query whenever there is a new set of rows.
First you should not be detaching the grid from the data source and then reattaching it. A lot goes on behind the scenes when you do that, that you don't want to be happening. And you shouldn't need that update and refresh of the grid either, not the creation of a new BindingSource.
In order to see the new set of records in the Grid, you need to reopen the query so that the new set of rows is in the result set. That should do it. If not, you can call RefreshAll() on the BindingSource which broadcasts to the grid to re display. But using the default BindingSource settings you shouldn't need that.
So, you only need to make the BindingSource once, attach it once, and then reopen the query whenever there is a new set of rows.
Thank you very much Laura, recode again only updating the data link without re-creating it.
This was the result.
METHOD PRIVATE VOID EnlazaTabla(): EMPTY TEMP-TABLE ttRegistro. hDataSet = DATASET dsRegistro:HANDLE. httRegistro = TEMP-TABLE ttRegistro:HANDLE. hBuffttRegistro = httRegistro:DEFAULT-BUFFER-HANDLE. DEFINE DATA-SOURCE fuenteDatos FOR ttMedicionesSucursal. hBuffttRegistro:ATTACH-DATA-SOURCE(DATA-SOURCE fuenteDatos:HANDLE,?,?,?). hDataSet:FILL(). /* Navigation query for Customer */ hRegistroQry = hDataSet:TOP-NAV-QUERY(). hRegistroQry:QUERY-PREPARE("PRESELECT EACH ttRegistro BY Fecha BY HoraCaptura"). hRegistroQry:QUERY-OPEN(). /* Display all Customer fields in the grid. */ BindingSource1:HANDLE = hRegistroQry. listaMediciones:DataSource = bindingSource1. END METHOD.
Don't know if you're saying if it worked or not. It looks right to me - i.e., different than it was before.
Hi Brian, I added the line of code that you shared with me.
What is the function of the instruction?
Hello Laura
Your suggestion works pretty well, thank you.
With BindingSource1:AutoSync set to true, the BindingSource will be notified automatically when the query is re-opened, so that it, in turn, can notify any controls that are bound to it to refresh. It's all in the doc :-)