Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

DataGridView not displaying data. 18 May 2023 06:25 #26375

  • RolWil
  • RolWil's Avatar
  • Topic Author


  • Posts: 29
  • 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” (
    ) 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:
    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:\Apps\HarborClipper\TargetDataTests\OSS"
                    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

    Please Log in or Create an account to join the conversation.

    DataGridView not displaying data. 18 May 2023 11:01 #26388

    • ic2
    • ic2's Avatar


  • Posts: 1662
  • 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:
    www.codeproject.com/Articles/24656/A-Det...ata-Binding-Tutorial
    www.c-sharpcorner.com/UploadFile/e95fe7/...g-with-windows-form/

    Dick

    Please Log in or Create an account to join the conversation.

    DataGridView not displaying data. 18 May 2023 11:43 #26389

    • wriedmann
    • wriedmann's Avatar


  • Posts: 3366
  • 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

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    DataGridView not displaying data. 18 May 2023 13:05 #26391

    • RolWil
    • RolWil's Avatar
    • Topic Author


  • Posts: 29
  • 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

    Please Log in or Create an account to join the conversation.

    DataGridView not displaying data. 18 May 2023 13:08 #26392

    • RolWil
    • RolWil's Avatar
    • Topic Author


  • Posts: 29
  • 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.

    Cheers,
    Roland
    Attachments:

    Please Log in or Create an account to join the conversation.

    Last edit: by RolWil. Reason: typo

    DataGridView not displaying data. 18 May 2023 15:53 #26394

    • RolWil
    • RolWil's Avatar
    • Topic Author


  • Posts: 29
  • 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()"
    PUBLIC CONSTRUCTOR()   STRICT//Form1
                InitializeComponent()
                
              SELF:dataGridView1:DataSource := SELF:bindingSource1
                           
                SET DEFAULT  TO  "E:\Apps\HarborClipper\TargetDataTests\OSS"
                USE BFMB
                    
                     MessageBox.Show("Rec's " + str(BFMB->(reccount())))
                    
                    
                VAR oDataSource := DbDataSource()
                SELF:bindingSource1:DataSource := oDataSource
                RETURN
                
            END CONSTRUCTOR

    Please Log in or Create an account to join the conversation.

    DataGridView not displaying data. 18 May 2023 16:18 #26395

    • ic2
    • ic2's Avatar


  • Posts: 1662
  • 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

    Please Log in or Create an account to join the conversation.

    DataGridView not displaying data. 19 May 2023 20:01 #26406

    • RolWil
    • RolWil's Avatar
    • Topic Author


  • Posts: 29
  • Sorry, misunderstanding: I found a missing line of code, but inserting it did NOT fix the problem.

    Please Log in or Create an account to join the conversation.

    DataGridView not displaying data. 19 May 2023 20:08 #26407

    • robert
    • robert's Avatar


  • Posts: 3588
  • 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

    Please Log in or Create an account to join the conversation.

    DataGridView not displaying data. 20 May 2023 15:50 #26410

    • RolWil
    • RolWil's Avatar
    • Topic Author


  • Posts: 29
  • 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:

    Please Log in or Create an account to join the conversation.

    DataGridView not displaying data. 20 May 2023 17:09 #26411

    • wriedmann
    • wriedmann's Avatar


  • Posts: 3366
  • Hi Roland,
    the correct video in X# Academy is this one:

    And the download is here:
    www.xsharp.eu/itm-downloads/download?pat...aBinding_Samples.zip

    And I have tried to run the sample, and on my machine it definitely works.
    It is the sample DBFData, and you have to change the "set default to" statement to the folder where you have expanded the sample code.
    InitializeComponent()
                SELF:dataGridView1:DataSource := self:bindingSource1
                SET DEFAULT TO C:\VFF\Samples\Data
                USE Customers
                VAR oDataSource :=  DbDataSource()
                oDataSource:ShowDeleted := FALSE
                oDataSource:ShowRecno   := FALSE
                SELF:bindingSource1:DataSource := oDataSource

    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    DataGridView not displaying data. 20 May 2023 17:28 #26412

    • wriedmann
    • wriedmann's Avatar


  • Posts: 3366
  • Hi Roland,
    I have found the problem in your sample:

    You had defined the autogeneration of columns to false, and therefor the grid had no idea what to display.
    Either set the autogeneration to on (what I have done), then the grid displays all fields in the table, or manually define your columns.
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it
    Attachments:

    Please Log in or Create an account to join the conversation.

    DataGridView not displaying data. 20 May 2023 17:34 #26413

    • wriedmann
    • wriedmann's Avatar


  • Posts: 3366
  • Hi Dick,

    you should really take the time and look and both the session video and the samples!

    I think they are really useful for everyone, and if the devteam adds some things (like filling the DbDataSource directly from a filename, indicating order and RDD) this could be really a widely used class.

    So again my recommendationto all here: take your time and look at this video:

    It is really great to see also for VO people like me.

    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    DataGridView not displaying data. 23 May 2023 01:59 #26424

    • RolWil
    • RolWil's Avatar
    • Topic Author


  • Posts: 29
  • Thank you Wolfgang,

    That did indeed do the trick! Also, thanks for the source code link from the Fox event.

    I had looked at all the properties for the dataGridView and hadn't found anything. But setting it using code worked. Beautiful.

    Cheers,
    Roland

    Please Log in or Create an account to join the conversation.

    DataGridView not displaying data. 23 May 2023 22:09 #26428

    • ic2
    • ic2's Avatar


  • Posts: 1662
  • Hello Wolfgang,

    you should really take the time and look and both the session video and the samples!

    I've watched it. I understand this is a partly 'code generated' version of what I used earlier and as Robert says somewhere in the presentation"It's complicated" . And that it is indeed, it's (at least in the background, is is certainly not a one line code matter).

    I do acknowledge that there are certain situation in which data binding has advantages. But if these situations do not occur, I stay away from databinding as far as possible. I've lost too much time in the past trying to find out why some data are not refreshed while being unable to debug this step by step like your own code to fill the data.

    Dick

    Please Log in or Create an account to join the conversation.

    DataGridView not displaying data. 24 May 2023 04:51 #26429

    • wriedmann
    • wriedmann's Avatar


  • Posts: 3366
  • Hi Dick,
    then your experience is exactly the opposite of mine: I'm using databinding whenever possible, sometimes by expanding the WPF GUI classes to make properties bindable that are not bindable by default (like binding the enter key on an edit control to a command in the viewmodel).
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1