Hi All,
Does anyone know If I can list items from the bottom of a Data grid up?
Do I need to add blank spaces in and remove them or can the data grid be set to display from the bottom of the grid?
[Solved] DataGrid View
-
- Posts: 363
- Joined: Wednesday 2nd December 2020 12:11am
- Location: Northampton, England
- Contact:
[Solved] DataGrid View
Last edited by AndyGable on Sunday 9th July 2023 5:27pm, edited 2 times in total.
Re: DataGrid View
What are you trying to achieve?
Can you give me an example maybe?
Can you give me an example maybe?
Last edited by gbWilly on Saturday 1st July 2023 2:53pm, edited 1 time in total.
gbWilly
- Dutch translation for Gambas3
- Gambas wiki content contributer
... there is always a Catch if things go wrong!
- Dutch translation for Gambas3
- Gambas wiki content contributer
... there is always a Catch if things go wrong!
Re: DatagGrid View
oops. might have been one of mine that escaped.
Have you ever noticed that software is never advertised using the adjective "spreadable".
-
- Posts: 363
- Joined: Wednesday 2nd December 2020 12:11am
- Location: Northampton, England
- Contact:
Re: DataGrid View
Sorry guys I did not notice I spelt that wrong.
Basically I just want the list of things to start at the bottom and move up instead of at the top and move down.
Basically I just want the list of things to start at the bottom and move up instead of at the top and move down.
Re: DataGrid View
I presume you are talking about DataView (part of gb.db.form).
So, for example, you have 10 records that need to populate the DataView
Normal top down manner of populating the DataView is:
in this order
You now want the populating going as follows and in this order:
Is this what you want? And if so, is there any special reason for wanting this?
So, for example, you have 10 records that need to populate the DataView
Normal top down manner of populating the DataView is:
Code: Select all
Record1 in row1
Record2 in row2
....
Record9 in row9
Record10 in row10
You now want the populating going as follows and in this order:
Code: Select all
Record10 in row10
Record9 in row9
....
Record2 in row2
Record1 in row1
gbWilly
- Dutch translation for Gambas3
- Gambas wiki content contributer
... there is always a Catch if things go wrong!
- Dutch translation for Gambas3
- Gambas wiki content contributer
... there is always a Catch if things go wrong!
-
- Posts: 363
- Joined: Wednesday 2nd December 2020 12:11am
- Location: Northampton, England
- Contact:
Re: DataGrid View
What I would like is the first item to show at the bottom and then the second to show underneath that and have them move up the screen.
I want this as it is part of my EPoS application
I want this as it is part of my EPoS application
Re: DataGrid View
Ok, so you don't get your data from a database, thus do not need DataView (from gb.db.form)
I guess you are talking about GridView then.
You want:
Upon adding Data2 you want:
And so on...
Just trying to wrap my head around what you exactly want.
If that is what you want you would:
1. Need to know how much data you will have, so you can create the proper sized GridView.
2. Create the GridView in the proper size
3. Add data to the bottom row and Move existing data up
Just a quick and dirty example.
I did this on an form with a GridView1 and a btnAdd (button):
GridView on the wiki: https://gambaswiki.org/wiki/comp/gb.qt4/gridview
Attached is the project (it is Gambas 3.15.2) so do a 'Compile All' before running on another version of Gambas3
I guess you are talking about GridView then.
You want:
Code: Select all
Data1 in row 10
Code: Select all
Data1 move to row 9
Data2 in row 10
Just trying to wrap my head around what you exactly want.
If that is what you want you would:
1. Need to know how much data you will have, so you can create the proper sized GridView.
2. Create the GridView in the proper size
3. Add data to the bottom row and Move existing data up
Just a quick and dirty example.
I did this on an form with a GridView1 and a btnAdd (button):
Private $iNumData As Integer
Public Sub Form_Open()
Me.Center
GridView1.Columns.Count = 2
GridView1.Rows.Count = 10
GridView1.Rows.Height = 28
GridView1.Columns[0].Width = 100
GridView1.Columns[1].Width = 75
End
Public Sub btnAdd_Click()
Dim iX As Integer
Inc $iNumData
'Move existing data one up
For iX = 0 To 8
GridView1[iX, 0].Text = GridView1[iX + 1, 0].Text
GridView1[iX, 1].Text = GridView1[iX + 1, 1].Text
Next
'Add the new data in the bottom row
GridView1[9, 0].Text = $iNumData
GridView1[9, 1].Text = "Data" & $iNumData
'Disable adding when grid is full
If $iNumData = 10 Then btnAdd.Enabled = False
End
GridView on the wiki: https://gambaswiki.org/wiki/comp/gb.qt4/gridview
Attached is the project (it is Gambas 3.15.2) so do a 'Compile All' before running on another version of Gambas3
- Attachments
-
- Test-0.0.1.tar.gz
- (11.76 KiB) Downloaded 96 times
gbWilly
- Dutch translation for Gambas3
- Gambas wiki content contributer
... there is always a Catch if things go wrong!
- Dutch translation for Gambas3
- Gambas wiki content contributer
... there is always a Catch if things go wrong!
-
- Posts: 363
- Joined: Wednesday 2nd December 2020 12:11am
- Location: Northampton, England
- Contact:
Re: DataGrid View
ok
so this is what I am having at the moment
I would like the items to list From the bottom and not from the top
so it would look a little like this
This is the code I am using the create the grid
This is the code I am using to add a single item to the grid
Is what I want to do even possible with the gridview component? if not I can just stick with it listing from the top
so this is what I am having at the moment
I would like the items to list From the bottom and not from the top
so it would look a little like this
This is the code I am using the create the grid
frmSalescreen.GridCurrentSale.Clear
With frmSalescreen.GridCurrentSale
.Columns.Count = 4
.Columns[0].Width = 450
.Columns[1].Width = 105
.Columns[2].Width = 15
.Columns[3].Width = 20
.Columns[0].Alignment = Align.BottomLeft 'Desciption
.Columns[1].Alignment = Align.Right 'Price
.Columns[2].Alignment = Align.BottomLeft 'Discout exempt
.Columns[3].Alignment = Align.BottomLeft 'VAT
.Rows.Count = 0
End With
This is the code I am using to add a single item to the grid
Dim RowCount As Integer = frmSalescreen.GridCurrentSale.Rows.Count
frmSalescreen.GridCurrentSale.Rows.Count = RowCount + 1
frmSalescreen.GridCurrentSale[RowCount, 0].Text = Line1
frmSalescreen.GridCurrentSale[RowCount, 1].Text = Price
frmSalescreen.GridCurrentSale[RowCount, 2].Text = PriceOptions
frmSalescreen.GridCurrentSale[RowCount, 3].Text = VATCode
frmSalescreen.GridCurrentSale.Columns[1].Alignment = Align.Right 'Price
frmSalescreen.GridCurrentSale.Select(RowCount, 1) ' Set last row
Is what I want to do even possible with the gridview component? if not I can just stick with it listing from the top
Re: DataGrid View
To list from the bottom you will need to create a GridView with all empty rows.
Number of rows needs to be enough to have the last row at the bottom. (in my example 10 rows)
Private $iNumData As Integer
Private $iMax As Integer 'Holds the number of rows in GridView1
Public Sub Form_Open()
Me.Center
With GridView1
.Columns.Count = 3
.Rows.Count = 10
.Rows.Height = 21
.Columns[0].Width = 350
.Columns[1].Width = 85
.Columns[2].Width = 15
.Columns[0].Alignment = Align.BottomLeft 'Desciption
.Columns[1].Alignment = Align.Right 'Price
.Columns[2].Alignment = Align.Center 'Datanumber
End With
'I start with 10 emty rows, to enable writing to the bottom
$iMax = GridView1.Rows.Count
End
Now, if you start adding content to the bottom row GridView , data already present will have move up.
Once the first row (top row) is filled you need to start adding a new row below when adding new data.
When adding a new row and data, the GridView needs to scroll up to make the latest addition visible.
This will make the first row disappear, but it is still there, just not visible (as I removed the scroll bar for my GridView, but scrolling with mouse will work if you want to see first row)
Public Sub btnAdd_Click()
Dim iX As Integer
Inc $iNumData
'Once visible rows are filled we start adding a new row and inc $iMax
If $iNumData > 10 Then
Inc GridView1.Rows.Count
Inc $iMax
Endif
Debug "Number of rows: " & GridView1.Rows.Count
'For the first 10 rows only we move up data and fill in the previous blank rows
If $iNumData <= 10 Then
For iX = 0 To $iMax - 2
GridView1[iX, 0].Text = GridView1[iX + 1, 0].Text
GridView1[iX, 1].Text = GridView1[iX + 1, 1].Text
GridView1[iX, 2].Text = GridView1[iX + 1, 2].Text
Next
Endif
'Write data to the bottom row
GridView1[$iMax - 1, 0].Text = $iNumData
GridView1[$iMax - 1, 0].Text = "Catbury's Cream Egg"
GridView1[$iMax - 1, 1].Text = "€ 0.65"
GridView1[$iMax - 1, 2].Text = $iNumData
'To try and make gridview scroll up once filled, so lowest row stays visible
GridView1.ScrollY = $iMax * 21 '<-- number of rows * row height
Debug "ScrollY: " & GridView1.ScrollY
End
I my example I add the data with some buttons (each giving a different article), but data can come from a table with articles as well if needed, that is all up to you. And when working with tables you can use TableView (based on GridView) so works the same. But, it is possible to start filling a GridView as you would like it as is shown in my project.
Added the full project so you can fiddle around with it.
- Attachments
-
- Test-0.0.2.tar.gz
- (12.38 KiB) Downloaded 93 times
gbWilly
- Dutch translation for Gambas3
- Gambas wiki content contributer
... there is always a Catch if things go wrong!
- Dutch translation for Gambas3
- Gambas wiki content contributer
... there is always a Catch if things go wrong!
-
- Posts: 363
- Joined: Wednesday 2nd December 2020 12:11am
- Location: Northampton, England
- Contact:
Re: DataGrid View
Thank you gbWillygbWilly wrote: ↑Sunday 2nd July 2023 3:29pm I my example I add the data with some buttons (each giving a different article), but data can come from a table with articles as well if needed, that is all up to you. And when working with tables you can use TableView (based on GridView) so works the same. But, it is possible to start filling a GridView as you would like it as is shown in my project.
Added the full project so you can fiddle around with it.
That was just what I was looking for I will implement the code you provided as a Option during set up so customers have a choice of having it from the top down or the bottom up
Thank you again.