xsharp.eu • DataGridView not displaying data.
Page 1 of 2

DataGridView not displaying data.

Posted: Thu May 18, 2023 4:25 am
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

DataGridView not displaying data.

Posted: Thu May 18, 2023 9:01 am
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

DataGridView not displaying data.

Posted: Thu May 18, 2023 9:43 am
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

DataGridView not displaying data.

Posted: Thu May 18, 2023 11:05 am
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

DataGridView not displaying data.

Posted: Thu May 18, 2023 11:08 am
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 908 times
Cheers,
Roland

DataGridView not displaying data.

Posted: Thu May 18, 2023 1:53 pm
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

DataGridView not displaying data.

Posted: Thu May 18, 2023 2:18 pm
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

DataGridView not displaying data.

Posted: Fri May 19, 2023 6:01 pm
by RolWil
Sorry, misunderstanding: I found a missing line of code, but inserting it did NOT fix the problem.

DataGridView not displaying data.

Posted: Fri May 19, 2023 6:08 pm
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

DataGridView not displaying data.

Posted: Sat May 20, 2023 1:50 pm
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


.