I am using Boa constructor and python2.3
I have a grid with lets say 3 columns and 25 rows and all the cells have numbers
I want to add contents of column 1 and display in textctrl1, total of column 2 in text ctrl 2 and total of column 3 in textctrl3
What i am doing right now is as follows -
Number_of_rows_Grid1 = self.grid1.GetNumberRows()
-
total = 0
-
for all_rows_in_grid1 in range (0,Number_of_rows_Grid1):
-
cell_value = self.grid1.GetCellValue(all_rows_in_grid1, 1)
-
total = total + cell_value
-
string_total = str(total)
-
self.textCtrl1.Value = string_total
I repeat the same process for column 2 and column 3 and assign them to textctrl2 and textctrl3 respectively
But If I want to do the following how do i assign the totals to the respective text ctrl -
Number_of_rows_Grid1 = self.grid1.GetNumberRows()
-
total = 0
-
for all_columns_in_grid1 in range (0,3):
-
for all_rows_in_grid1 in range (0,Number_of_rows_Grid1):
-
cell_value = self.grid1.GetCellValue(all_rows_in_grid1, 1)
-
total = total + cell_value
-
string_total = str(total)
-
2 1676
I am using Boa constructor and python2.3
I have a grid with lets say 3 columns and 25 rows and all the cells have numbers
I want to add contents of column 1 and display in textctrl1, total of column 2 in text ctrl 2 and total of column 3 in textctrl3
What i am doing right now is as follows -
Number_of_rows_Grid1 = self.grid1.GetNumberRows()
-
total = 0
-
for all_rows_in_grid1 in range (0,Number_of_rows_Grid1):
-
cell_value = self.grid1.GetCellValue(all_rows_in_grid1, 1)
-
total = total + cell_value
-
string_total = str(total)
-
self.textCtrl1.Value = string_total
I repeat the same process for column 2 and column 3 and assign them to textctrl2 and textctrl3 respectively
But If I want to do the following how do i assign the totals to the respective text ctrl -
Number_of_rows_Grid1 = self.grid1.GetNumberRows()
-
total = 0
-
for all_columns_in_grid1 in range (0,3):
-
for all_rows_in_grid1 in range (0,Number_of_rows_Grid1):
-
cell_value = self.grid1.GetCellValue(all_rows_in_grid1, 1)
-
total = total + cell_value
-
string_total = str(total)
-
Oh boy, sounds like fun! You may not be aware that it's OK to add your own stuff to the __init__() function of a Boa generated Frame, etc. I use this trick often: - # Boa's widget layout above + next 2 lines
-
def __init__(self, parent):
-
self._init_ctrls(parent)
-
# your code here
-
self.tcList = (self.textCtrl1, self.textCtrl2, self.textCtrl3)
-
-
def OnWhatever(self, event):
-
for col in range (3): # range() starts at zero by default
-
total = 0 # reset total for each column
-
for row in range (Number_of_rows_Grid1): # I think it's more clear this way
-
cell_value = self.grid1.GetCellValue(row, col)
-
total += cell_value # another shortcut
-
string_total = str(total)
-
self.tcList[col].SetValue(string_total)
This is not tested, but should serve to give you the basic idea.
Thanks a lot.... the array idea was awesome... it did work beautifully.
Redused about 115 lines of code to 20 lines. - Number_of_rows_Grid1 = self.grid1.GetNumberRows()
-
-
self.tcList = (self.textCtrl1, self.textCtrl2, self.textCtrl4, self.textCtrl5, self.textCtrl7, self.textCtrl8)
-
col_list = (1, 2, 4, 5, 7, 8)
-
-
for col_index in range (0,6):
-
total = 0
-
for all_rows_grid1 in range(0,Number_of_rows_Grid1-1):
-
cell_value = self.grid1.GetCellValue(all_rows_grid1, col_list[col_index])
-
if cell_value:
-
cell_value = int (cell_value)
-
else:
-
cell_value = 0
-
-
total = total + cell_value
-
self.tcList[col_index].SetValue(str(total))
-
-
self.textCtrl3.Value = str(round(float(self.textCtrl2.Value)*100.00/float(self.textCtrl1.Value),2))
-
self.textCtrl6.Value = str(round(float(self.textCtrl5.Value)*100.00/float(self.textCtrl4.Value),2))
-
self.textCtrl9.Value = str(round(float(self.textCtrl8.Value)*100.00/float(self.textCtrl7.Value),2))
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Yaroslav Bulatov |
last post by:
I made an array of 10 million floats timed how long it takes to sum
the elements, here's what I got (millis):
gcc -O2: 21
Python with numarray: 104
Python with Numeric: 302...
|
by: Don Sealer |
last post by:
I have about 40 different defects I'm tracking. I'd like to have all of
these defects totaled individually, both by month and by year. I'd like to
show these results in a report. I know I could...
|
by: John Ruiz |
last post by:
Greetings,
I originally posted this to
microsoft.public.dotnet.framework.aspnet.datagridcontrol two weeks ago, but
no one was able to answer.
I am unable to dynamically add columns to a...
|
by: pmud |
last post by:
Hi,
I have 2 questions:
1. I have an editable data grid with 21 columns. I need to edit only 2
cloumns in this data grid. But when the grid is displayed in Edit mode, all
the columns show long...
|
by: NowItsWhatever |
last post by:
In query DESIGN view, how do I automatically "fit" the columns in the
table/field grid to the lengths of the table and field names (including any
functions applied to the fields). I am not talking...
|
by: bappelsin |
last post by:
Hello,
I have a problem with the datagridview. I have a view with around 25
different columns. To make life easier for the users I have implemented
a popup dialog where the user can select which...
|
by: Earl |
last post by:
I have somewhat of an interesting scenario:
The form allows the user to select a service, which populates a a grid of
product information related to that service ("service grid"). The user can...
|
by: lethek39 |
last post by:
Hey
I have been trying to figure out how to sum rows and columns in a matrix square. I also have been trying to get the program to list the numbers of the diagonal in the matrix. So far this is the...
|
by: msgjunkie |
last post by:
I have 3 related tables in a DataSet - Customers, Products and Orders.
I am trying to create an "editable" DataGridView which, ideally, will contain columns from all the tables. I have tried...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |