DataGridView not displaying data.

This forum is meant for questions and discussions about the X# language and tools
RolWil
Posts: 68
Joined: Mon Jul 18, 2022 3:16 am

DataGridView not displaying data.

Post by RolWil »

I’m familiarizing myself with XSharp data binding.

I have a form with a DataGrid View (dataGridView1), a navigator control (bindingNavigator1), a Binding source (bindingSource1) and a binding navigator control (bindingNavigator1).

I based this on “How To Add An Icon To Your C# Application | Visual Studio 2019” (https://www.youtube.com/watch?v=0OSUwe2LdqU) at around 44:00 on the XSharp Youtube channel.

My project’s dialect is set to Harbour, my additional references are XSharp.core, XSharp.RT and XSharp.Data.

Problem: the MessageBox indicates the correct number of records in the BFCL table, but the Data Grid View remains a grey box – no columns, no data,

My code:

Code: Select all

USING System
USING System.Collections.Generic
USING System.ComponentModel
USING System.Data
USING System.Drawing
USING System.Linq

USING System.Text
USING System.Threading.Tasks

USING System.Windows.Forms

BEGIN NAMESPACE DBF_Test1

    PUBLIC PARTIAL CLASS Form1 ;
        INHERIT System.Windows.Forms.Form

        PUBLIC CONSTRUCTOR()   STRICT//Form1
            InitializeComponent()            
          
            SET DEFAULT  TO  "E:AppsHarborClipperTargetDataTestsOSS"
                USE BFMB
                
                 MessageBox.Show("Rec's " + str(BFMB->(reccount())))
                
                
            VAR oDataSource := DbDataSource()
            SELF:bindingSource1:DataSource := oDataSource
            RETURN
            
        END CONSTRUCTOR
        

    END CLASS 
END NAMESPACE
Where am I going wrong?

Thanks,
Roland
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

DataGridView not displaying data.

Post by ic2 »

Hello Roland,

Personally I hate databinding because you can't use debugging to see why something is wrong. But I have applied it a few times and I can tell you that you must do a lot more than 1 line of code.

Here a few sites explaining it:
https://www.codeproject.com/Articles/24 ... g-Tutorial
https://www.c-sharpcorner.com/UploadFil ... dows-form/

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

DataGridView not displaying data.

Post by wriedmann »

Hi Dick,
PMFJI, but this may be true if you don't have a Robert behind.
I have seen samples where it is actually only that code.
@Roland: try to set the VFP dialect, maybe it works then.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
RolWil
Posts: 68
Joined: Mon Jul 18, 2022 3:16 am

DataGridView not displaying data.

Post by RolWil »

Thanks Dick,

That is indeed more code in those links. But if you watch the Video @ around 44:00, you'll see it working with just a few lines; that's the code I copied. The 'bindingNavigator' control works, gives the correct record count and one can add records)

Roland
RolWil
Posts: 68
Joined: Mon Jul 18, 2022 3:16 am

DataGridView not displaying data.

Post by RolWil »

Thank you Wolfgang;

I had tried VFO since that's what Robert is using in the video but it didn't work. So now I tried the other dialects ... and no go. As I wrote to Dick, the 'bindingNavigator' control actually works - except deleting which results in an error.
DataGridView.jpg
DataGridView.jpg (14.99 KiB) Viewed 904 times
Cheers,
Roland
RolWil
Posts: 68
Joined: Mon Jul 18, 2022 3:16 am

DataGridView not displaying data.

Post by RolWil »

Darn it. I rechecked my code .. .and found that I had overlooked a line of code from the video. I got all excited thinking that was the issue .. alas, it was not. The missing line was: "SELF:dataGridView1:DataSource := SELF:bindingSource1" immediately after "InitializeComponent()"

Code: Select all

        PUBLIC CONSTRUCTOR()   STRICT//Form1
            InitializeComponent()
            
          SELF:dataGridView1:DataSource := SELF:bindingSource1
                       
            SET DEFAULT  TO  "E:AppsHarborClipperTargetDataTestsOSS"
            USE BFMB
                
                 MessageBox.Show("Rec's " + str(BFMB->(reccount())))
                
                
            VAR oDataSource := DbDataSource()
            SELF:bindingSource1:DataSource := oDataSource
            RETURN
            
        END CONSTRUCTOR
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

DataGridView not displaying data.

Post by ic2 »

Hello Richard,

Good you found it! That is indeed a lot les code than I had to use (in C#) to get things working.

As you can see in the samples....

Dick
RolWil
Posts: 68
Joined: Mon Jul 18, 2022 3:16 am

DataGridView not displaying data.

Post by RolWil »

Sorry, misunderstanding: I found a missing line of code, but inserting it did NOT fix the problem.
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

DataGridView not displaying data.

Post by robert »

Roland,
Can you create a small example program demonstrating what you are doing and mail that to me (or attach it here)

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
RolWil
Posts: 68
Joined: Mon Jul 18, 2022 3:16 am

DataGridView not displaying data.

Post by RolWil »

Hi Robert, thanks. I've ZIP'ed up the entire project from the root.

Is the source code from that online FOX conference available?

Cheers
Roland


.
Attachments
DBF_Test1.zip
(1.06 MiB) Downloaded 98 times
Post Reply