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

TOPIC: BUG - Visual Studio losing my code in a WinForm prg file!!!

BUG - Visual Studio losing my code in a WinForm prg file!!! 30 May 2020 15:11 #14770

  • FoxProMatt's Avatar

  • FoxProMatt

  • Topic Author


  • Posts: 391
  • This happens every time I edit a WinForm in X# FoxPro project.

    I can tell you the steps to reproduce it:

    1. Open a WinForm in the visual designer. Design a simple form with some UI Controls.
    2. Press F7 and add some custom code to the PRG.
    Save the Code changes in the PRG.
    3. Click on the Form Designer tab.
    4. Move one of the UI controls to a new position on the form canvas.
    5. Save the Form from the Form Designer.
    6. Press F7 to view the PRG code.
    7. Be surprised when you see that your custom code has been stripped out of the PRG file.


    It seems that the Form Designer will just regenerate the basic code for the form and wipe out your custome code.

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

    Last edit: by FoxProMatt.

    BUG - Visual Studio losing my code in a WinForm prg file!!! 30 May 2020 15:19 #14771

  • robert's Avatar

  • robert


  • Posts: 1746
  • Matt,
    If your custom code contains UDCs such as the database commands, then this is a known issue and it is already solved in our internal build.

    Robert
    XSharp Development Team
    The Netherlands

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

    BUG - Visual Studio losing my code in a WinForm prg file!!! 30 May 2020 15:21 #14773

  • FoxProMatt's Avatar

  • FoxProMatt

  • Topic Author


  • Posts: 391
  • Here is 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 WindowsFormsApplication2
        Public Partial Class Form1 ;
    	    Inherit System.Windows.Forms.Form
        
    	Public names As BindingList<String>
            Public Constructor()   Strict//Form1
                
                InitializeComponent()
    
                Use Employee
                Var employeeDataSource = DbDataSource()
                listBox1.DataSource = employeeDataSource
                listBox1.DisplayMember = "Last_name"
    			
        	Private Method bindingSource1_CurrentChanged(sender As Object, e As System.EventArgs) As Void Strict
                    Return
        
    	Private Method Form1_Load(sender As Object, e As System.EventArgs) As Void Strict
                    Return
        
    	Private Method button1_Click(sender As Object, e As System.EventArgs) As Void Strict
        
    	Private Method listBox1_SelectedIndexChanged(sender As Object, e As System.EventArgs) As Void Strict
                Return
    
    End Class 
    
    End Namespace
    

    Attachments:

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

    Last edit: by FoxProMatt.

    BUG - Visual Studio losing my code in a WinForm prg file!!! 30 May 2020 15:23 #14774

  • robert's Avatar

  • robert


  • Posts: 1746
  • Matt,
    It is the USE command that causes the problem (fixed in next build).
    If you replace it with DbUseArea(,,"Employee")
    then it will work and the code will not be removed

    Robert
    XSharp Development Team
    The Netherlands

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

    BUG - Visual Studio losing my code in a WinForm prg file!!! 30 May 2020 15:48 #14776

  • FoxProMatt's Avatar

  • FoxProMatt

  • Topic Author


  • Posts: 391
  • Robert- I need some other advice about the style of programming...

    Given that the binding source is the entire employee DBF and the currently displayed item in the list box is the last name, how can I get the entire data row from the selected entry in the list box?

    What I would want next is to know the ID value (from the ID field in the DBF) for the selected item in the list box.

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

    BUG - Visual Studio losing my code in a WinForm prg file!!! 30 May 2020 20:23 #14778

  • robert's Avatar

  • robert


  • Posts: 1746
  • Matt,

    Listboxes are not designed to display more than one column.
    To get the ID value back from the listbox you need to set the "ValueMember" of the listbox to the name of that column. You can also use "RecNo" as field name, since we have added a RecNo property to every row in the DbDataSource
    If you want multiple columns you should check out the ListView control or the DataGridview control

    Robert
    XSharp Development Team
    The Netherlands

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

    BUG - Visual Studio losing my code in a WinForm prg file!!! 31 May 2020 05:55 #14779

  • FoxProMatt's Avatar

  • FoxProMatt

  • Topic Author


  • Posts: 391
  • Robert - I've looked at other .Net C# Examples about BindingSource and ListBox control, and C# can give the entire object from the DataSource from the SelectedItem of the ListBox, if you Cast it to the correct Type.

    Given this Class to represent the exact fields in the DBF:
    Public Class Employee
    
       Public First_Name As String
       Public Last_Name As String
       Public Employee_Id As Int
    
    End Class

    Then if I create a DbDataSource from the DBF and set that as the DataSource on the listbox, then this code should let me access any property from the DataSource record (which would com from each DBF row):
    Var id = ((Employee)listBox1.SelectedItem).Employee_Id
    Var firstName = ((Employee)listBox1.SelectedItem).First_Name

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

    Last edit: by FoxProMatt.

    BUG - Visual Studio losing my code in a WinForm prg file!!! 31 May 2020 15:05 #14783

  • robert's Avatar

  • robert


  • Posts: 1746
  • Matt,
    The C# example is not really comparable, since the data source for this example apparently is a list of Employee objects.
    The DbDataSource() does not use this kind of objects, but uses a DbRecord, a generic class, that uses some 'advanced'
    tricks to tell the listbox (or any other class that it binds to) to make it believe that it has properties with the names
    of the fields in the DBF file that it exposes.
    The only 'Real' properties this DbRecord class has are RecNo and Deleted
    This class also has an 'indexer' property that takes a field name or field number and allows you to read/write these fields.

    So what you can do is:
    - cast the value of the selected item to DbRecord
    VAR oRec := (XSharp.DbRecord) listBox1.SelectedItem
      var firstName := oRec["FirstName"]
      // or assuming that this is the first field in the DBF
      // var firstName := oRec[1]

    I hope this helps.

    Robert
    XSharp Development Team
    The Netherlands

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

    BUG - Visual Studio losing my code in a WinForm prg file!!! 31 May 2020 18:36 #14785

  • FoxProMatt's Avatar

  • FoxProMatt

  • Topic Author


  • Posts: 391
  • This looks like a solution that will work perfectly for what I want to do.

    Thanks!

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

    • Page:
    • 1