Adrian Klaver wrote:
> I may be reinventing the wheel here, but I could find no method in dGrid to
> find the column index for a column by using its DataField name.
> getColByDataField() returns a column name but no index value. The problem
> lies in using setValue() where a row and column index are needed. To get
> around this I modified getColByDataField():
>
> def getColByDataField(self, df,index = False):
> """ Given a DataField value, return the corresponding column."""
> try:
> col = [(idx,self.Columns[idx]) for idx in
> range(len(self.Columns))if
> self.Columns[idx].DataField == df][0]
> if index == False:
> ret = col[1]
> else:
> ret = col
> #ret = [col for col in self.Columns
> # if col.DataField == df][0]
> except IndexError:
> ret = None
> return ret
>
> The default behavior is to return the same information as in the original
> function. If index = True then a tuple is returned with the index and column.
> I don't know if this is useful or not. If not I will create a private
> function to do this and leave the original alone.
It is useful. The usual Dabo style would be to refactor this into 2
functions, like:
def getColByDataField(self, df):
return self.Columns[self.getColIdxByDataField(df)].
def getColIdxByDataField(self, df):
for idx, col in self.Columns:
if col.DataField == df:
return idx
return None
These are untested; let me know how they work!
Paul
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/[EMAIL PROTECTED]