Need Help with Datagrid

This forum is meant for questions about the Visual FoxPro Language support in X#.

User avatar
Florentin Lüdeking
Posts: 11
Joined: Tue Aug 02, 2022 1:42 pm

Need Help with Datagrid

Post 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
Attachments
Screenshot 2022-10-12 131808.png
Screenshot 2022-10-12 131808.png (18.57 KiB) Viewed 1910 times
User avatar
wriedmann
Posts: 3775
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Need Help with Datagrid

Post by wriedmann »

Hi Florentin,
what do you like to accomplish with the Windows Forms DataGrid?
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Florentin Lüdeking
Posts: 11
Joined: Tue Aug 02, 2022 1:42 pm

Need Help with Datagrid

Post by Florentin Lüdeking »

Hi Wolfgang,
i would like to use it like the grid in the Visual FoxPro Forms!

Florentin
User avatar
wriedmann
Posts: 3775
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Need Help with Datagrid

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Jamal
Posts: 322
Joined: Mon Jul 03, 2017 7:02 pm

Need Help with Datagrid

Post 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
User avatar
Florentin Lüdeking
Posts: 11
Joined: Tue Aug 02, 2022 1:42 pm

Need Help with Datagrid

Post 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
Delete.png (41.05 KiB) Viewed 1931 times
The second screenshot shows what happens if i delete and then rebind the DataSource.
NewDataSourceSet.png
NewDataSourceSet.png (36.17 KiB) Viewed 1931 times

Im really lost on what to do :(

Florentin
User avatar
wriedmann
Posts: 3775
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Need Help with Datagrid

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Jamal
Posts: 322
Joined: Mon Jul 03, 2017 7:02 pm

Need Help with Datagrid

Post 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
User avatar
robert
Posts: 4555
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Need Help with Datagrid

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Florentin Lüdeking
Posts: 11
Joined: Tue Aug 02, 2022 1:42 pm

Need Help with Datagrid

Post by Florentin Lüdeking »

Robert,

thank you very much!
Post Reply