Page 1 of 2
Need Help with Datagrid
Posted: Wed Oct 12, 2022 11:22 am
by Florentin Lüdeking
Hey everyone
I need some help with the dataGridView because I don't really understand how to use it in X#
I am currently setting the datasource like this:
Code: Select all
this.dataGridView1.DataSource = DbDataSource()
If i use DELETE with SET DELETED ON this happens (See attachment)
What am i doing wrong?
Thank you very much
Florentin
Need Help with Datagrid
Posted: Wed Oct 12, 2022 12:09 pm
by wriedmann
Hi Florentin,
what do you like to accomplish with the Windows Forms DataGrid?
Wolfgang
Need Help with Datagrid
Posted: Wed Oct 12, 2022 12:14 pm
by Florentin Lüdeking
Hi Wolfgang,
i would like to use it like the grid in the Visual FoxPro Forms!
Florentin
Need Help with Datagrid
Posted: Wed Oct 12, 2022 12:23 pm
by wriedmann
Hi Florentin,
there are several mentions of this class in the forums here, so someone seems to have used it.
But I think you need Robert or Fabrice here....
Wolfgang
Need Help with Datagrid
Posted: Thu Oct 13, 2022 3:39 am
by Jamal
Hi Florentin,
I don't use FoxPro, however, after DELETE you may have to do:
this.dataGridView1.Update()
this.dataGridView1.Refresh()
If this does not work, try binding the grid again.
What happens if you reopen the form? Does the display of rows look the same?
HTH,
Jamal
Need Help with Datagrid
Posted: Thu Oct 13, 2022 6:06 am
by Florentin Lüdeking
Hi Jamal,
i tried all of your suggestions and sadly none of them work for me.
I am also using
SET DELETED ON
this is the code i use to set the DataSource:
Code: Select all
SELECT 0
USE kdstm ALIAS kdstm
this:dataGridView1:DataSource = DbDataSource()
If I want to delete something I used this code:
Code: Select all
DELETE
this:dataGridView1:Update()
this:dataGridView1:Refresh()
The first screenshot shows what happens if i just delete.
For some reason it doesn't hide the deleted row even though i use SET DELETED ON.
- Delete.png (41.05 KiB) Viewed 1812 times
The second screenshot shows what happens if i delete and then rebind the DataSource.
- NewDataSourceSet.png (36.17 KiB) Viewed 1812 times
Im really lost on what to do
Florentin
Need Help with Datagrid
Posted: Thu Oct 13, 2022 6:11 am
by wriedmann
Hi Florentin,
IMHO you need to wait what Robert says, and before he says something I'm pretty sure he needs some time to analyze that.
But AFAIK today is the first day of Virtual FoxFest, and maybe he had to prepare something for his presence there and was not able to check out your problem.
Wolfgang
Need Help with Datagrid
Posted: Thu Oct 13, 2022 8:55 pm
by Jamal
Hi Florentin,
Is the datasource a DBF or SQL?
What is the code behind in DbDataSource()?
Edit: I suggest you create a reproducible sample for the dev team to look at.
Jamal
Need Help with Datagrid
Posted: Fri Oct 14, 2022 7:09 am
by robert
Florentin,
Wolgang was right. I was busy with my session for Virtual FoxFest.
At first glance I think the problem is that the DbDataSource returns the # of records in the table when asked by the Grid for the # of rows. And it does not subtract the # of deleted rows. That would explain why there is an empty row at the bottom.
Give me some time to look at this.
The alternative solution would be to use the DbDataTable(). This reads the contents from the cursor in a (detached) DataTable. A deletion in the table will remove the DataRow (move it to a list of deleted rows).
The disadvantage of this approach is that you will have to write the changes back to the database when you commit the changes (with a button or when you close the form).
I showed how this can be done in my session for VFF a couple of years ago,
It boils down to:
Code: Select all
oTable := DbDataTable()
SELF:DataContext := oTable
.
.
.
DbTableSave(oTable)
To see what happens when save is executed, look here
https://github.com/X-Sharp/XSharpPublic ... e.prg#L113
I'll look into this asap.
Robert
Need Help with Datagrid
Posted: Fri Oct 14, 2022 7:57 am
by Florentin Lüdeking
Robert,
thank you very much!