wxGrid initialisation fails if zero record retrieved from DB

Hello,

I have a grid which uses PyGridTableBase which in turn retrieve record
from DB. However, if during the grid initialisation, the DB selection
criteria happen to retrieve 0 record, then all the wxGrid.SetColSize,
GetColLabelValue, etc will fail.

  Must I add a dummy record in the DB such that always at least one
  record will be retrieved? Any better other workaround?

Thanks in advance!

···

--
Best regards,
Herman

Hi Herman,

Herman Lo wrote:

Hello,

I have a grid which uses PyGridTableBase which in turn retrieve record
from DB. However, if during the grid initialisation, the DB selection
criteria happen to retrieve 0 record, then all the wxGrid.SetColSize,
GetColLabelValue, etc will fail.

Must I add a dummy record in the DB such that always at least one
record will be retrieved? Any better other workaround?

I came across the same problem. I solved it by adding a dummy record to "self.data" in PyGridTableBase if I see that the DB query returned no rows.

···

Thanks in advance!

Hello,

Must I add a dummy record in the DB such that always at least one
record will be retrieved? Any better other workaround?

I came across the same problem. I solved it by adding a dummy record to
"self.data" in PyGridTableBase if I see that the DB query returned no rows.

Thank!!! but I still have a feeling that this is not the right (or
best) way to do it... Does anybody else have a better solution or workaround?

but sei mo kan dao <==> Warner br :open_mouth:

···

--
Best regards,
Herman

Herman,

For some reason my mail gets rejected if I respond to your latest post on this.

Had another idea on how to handle this, see below.

Werner F. Bruhin wrote:

Hi Herman,

Herman Lo wrote:

Hello,

I have a grid which uses PyGridTableBase which in turn retrieve record
from DB. However, if during the grid initialisation, the DB selection
criteria happen to retrieve 0 record, then all the wxGrid.SetColSize,
GetColLabelValue, etc will fail.

Must I add a dummy record in the DB such that always at least one
record will be retrieved? Any better other workaround?

I came across the same problem. I solved it by adding a dummy record to "self.data" in PyGridTableBase if I see that the DB query returned no rows.

Changed GetNumberRows and GetNumberCols as follows:

    def GetNumberRows(self):
        if len(self.data):
            return len(self.data)
        else:
            return 0

    def GetNumberCols(self):
        return len(self.colLabels)

Note: self.colLabels is a list of my column headings, you might need to use something else to define the number of columns.

This gives me a grid with just the column headers and no rows - which is much nicer then having a blank row - thanks to you!

See you
Werner

···

Thanks in advance!

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

Hello Werner,

Werner F. Bruhin wrote:

Changed GetNumberRows and GetNumberCols as follows:

    def GetNumberRows(self):
        if len(self.data):
            return len(self.data)
        else:
            return 0

    def GetNumberCols(self):
        return len(self.colLabels)

Note: self.colLabels is a list of my column headings, you might need to
use something else to define the number of columns.

This gives me a grid with just the column headers and no rows - which is
much nicer then having a blank row - thanks to you!

Actually my existing code has similar code already:

    def GetNumberRows(self):
        return len(self.dataset)

    def GetNumberCols(self):
        return len(self.ni_hdr)
        
For me, the len() check you added was unnecessary as it would have been
an empty set if no record retrieved.

I am glad it somehow works for you. For me, the header is still empty
and also SetColSize will fails.

Thanks!!

Herman

···

--------------
but sei mo kan dao -- nei zen hai ho lark, bon ngoi coding &
debugging, but your ad hoc fix ho superficial ar and didnt really
fix it ga, nei yiu write a true test to sim sin tak ga, nei always
write buggy sw ga....emule already an example ... :open_mouth:

Hello Werner,

Tuesday, August 19, 2003, 6:17:57 PM, you wrote:

For some reason my mail gets rejected if I respond to your latest post
on this.

Had another idea on how to handle this, see below.
Changed GetNumberRows and GetNumberCols as follows:

    def GetNumberRows(self):
        if len(self.data):
            return len(self.data)
        else:
            return 0

    def GetNumberCols(self):
        return len(self.colLabels)

Hi,

Just curious, before this new change, how was your old code look like
in GetNumberRows(self) and GetNumberCols(self) ?
As it seem your change does not really related to the problem we have.
It should always behave like that whether we have that 0-record grid problem or not.
That is, it returns the correct number of records it retrieved (for
GetNumberRows).
I am still thinking of the real way of fixing it... :frowning:

Thanks
Herman

···

----
but sei mo kan dao inventing code ar...nei very like chong jok
lark..haha