Change column width in a DataView not working [solved]

Ask about the individual Gambas components here.
Post Reply
Zeke99
Posts: 12
Joined: Tuesday 12th January 2021 7:44pm

Change column width in a DataView not working [solved]

Post by Zeke99 »

I have a DataSource with a DataView inside.
I try to change the column width with DataView1.View.Columns[1] = 50 but recieves error "Not a field" (translated from swedish). Code below:

Code: Select all

'Module1
Public $MyConn As New Connection

Public Procedure Connect()
  
    $MyConn.Close()
    $MyConn.Type = "mysql"
    $MyConn.Host = "127.0.0.1"
    $MyConn.Login = "Loginname"
    $MyConn.Port = "3306"
    $MyConn.Name = "Tablename"
    $MyConn.Password = "pass"
    $MyConn.Open()   
End 

'FMain
Public Sub Form_Open()
  Dim Aheight As Integer
  Dim Awidth As Integer

  Module1.Connect() 'Establish connection to database
  DataSource1.Connection = Module1.$MyConn

  Aheight = Screens[0].AvailableHeight
  Awidth = Screens[0].AvailableWidth
  FMain.Width = Awidth
  FMain.Height = Aheight
  DataSource1.Height = (Aheight - 110)
  DataView1.Height = (Aheight - 115)
  DataSource1.Width = (Awidth - 110)
  DataView1.Width = (Awidth - 115)  
  DataView1.Labels = ["Datum", "Artikel", "Artno", "Antal", "Lev_antal", "Lev"]
  DataView1.Columns = ["order_sub_delivery_date", "order_sub_item", "order_sub_item_code", "order_sub_amount", "order_sub_delivered_amount", "order_sub_delivered"]

  DataView1.View.Columns[1] = 50   'It's here I recieve the error Inte ett fält (Not a field in english)
  
  Update_tableform() 'Populate listboxes based on data collected from db
End

Public Sub Update_tableform()

  DataSource1.Table = "SELECT order_sub_delivery_date, order_sub_item,  order_sub_item_code, order_sub_amount, order_sub_delivered_amount, order_sub_delivered FROM table_order_sub WHERE order_sub_delivered=0 ORDER BY order_sub_delivery_date"

End

Public Sub Timer1_Timer()

  DataView1.Update

End
Any suggestions what I'm doing wrong
Last edited by Zeke99 on Friday 19th April 2024 6:06pm, edited 1 time in total.
User avatar
BruceSteers
Posts: 1588
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Change column width in a DataView not working

Post by BruceSteers »

The code should look more like this...


DataView1.View.Columns[1].Width = 50



you are missing the Width property

DataView1.View.Columns[1] is a pointer to the the Column object not it's width property.

PS. It can help a lot to just try hitting . (dot/full stop) after anything and see if the auto-complete shows you something helpful :)

Hope that helps
If at first you don't succeed , try doing something differently.
BruceS
Zeke99
Posts: 12
Joined: Tuesday 12th January 2021 7:44pm

Re: Change column width in a DataView not working

Post by Zeke99 »

Tired yesterday when writing on the forum. Missed the .width.

I have tested DataView1.View.Columns[0].width=50, DataView1.GridView.Columns[0].width = 50, DataView.View.Column[0]=50 and many others with no luck.

Today I restarted the computer and Gambas. Did a sudo apt update/upgrade. Tested DataView1.View.Columns[0].width=50 and it works!
I don't know why two days testing of all thinkable code doesn't work and suddenly it works but I am happy!

Have a nice weekend and a special thanks to all of you answering questions!
Post Reply