From: Patrick A on
OK, I'm very close...but I'm getting poked in the eye by differing
types, and can't figure out how to convert
'System.String' to type 'System.Windows.Forms.DataGridViewColumn'

'My Declarations
Public Class MyGlobals
Public Shared TimersSortCol ' I have tried declaring this in
several ways...Nothing works on both sides.
Public Shared TimersSortOrd as String
End Class

'Getting the Values
'Get the TBL_TimersDataGridView sort order from the ini file
Dim strSortOrd As String =
MyGlobals.oIniFile.GetString("General", "SortOrd", "0")
MyGlobals.TimersSortOrd = strSortOrd
'returns a number

'Get the TBL_TimersDataGridView sort column from the ini file
Dim strSortCol As String =
MyGlobals.oIniFile.GetString("General", "SortCol", "0")
MyGlobals.TimersSortCol = strSortCol
'returns a number

'Using the Values
TBL_TimersDataGridView.Sort(MyGlobals.TimersSortCol,
MyGlobals.TimersSortOrd)

The error;

Unable to cast object of type 'System.String' to type
'System.Windows.Forms.DataGridViewColumn'.

Any suggestions?

Thanks,

Patrick

From: Andrew Morton on
Patrick A wrote:
> OK, I'm very close...but I'm getting poked in the eye by differing
> types, and can't figure out how to convert
> 'System.String' to type 'System.Windows.Forms.DataGridViewColumn'
>
> Any suggestions?

Without looking into it any depth, I can suggest iterating over the columns
and using the one which has a name which is the same as the stored value.
There might be a more direct way.

Something like:

dim selectedCol as datagridviewcolumn
for each dgvc as datagridviewcolumn in TBL_TimersDataGridView.Columns
if dgvc.Name=whatever then
selectedCol=dgvc
exit for
end if
next

Andrew


From: Patrick A on
Andrew,

Thanks for your reply, but I must be missing something - I'm not sure
how that sorts my column.

Can you provide a little more detail?

Patrick

On Mar 29, 6:00 am, "Andrew Morton" <a...(a)in-press.co.uk.invalid>
wrote:
> Patrick A wrote:
> > OK, I'm very close...but I'm getting poked in the eye by differing
> > types, and can't figure out how to convert
> > 'System.String'   to type   'System.Windows.Forms.DataGridViewColumn'
>
> > Any suggestions?
>
> Without looking into it any depth, I can suggest iterating over the columns
> and using the one which has a name which is the same as the stored value.
> There might be a more direct way.
>
> Something like:
>
> dim selectedCol as datagridviewcolumn
> for each dgvc as datagridviewcolumn in TBL_TimersDataGridView.Columns
>  if dgvc.Name=whatever then
>     selectedCol=dgvc
>     exit for
>  end if
> next
>
> Andrew

From: Andrew Morton on
Patrick A wrote:

> On Mar 29, 6:00 am, "Andrew Morton"
>> Patrick A wrote:
>>> OK, I'm very close...but I'm getting poked in the eye by differing
>>> types, and can't figure out how to convert
>>> 'System.String' to type 'System.Windows.Forms.DataGridViewColumn'
>>
>>> Any suggestions?

>>
>> Without looking into it any depth, I can suggest iterating over the
>> columns and using the one which has a name which is the same as the
>> stored value. There might be a more direct way.
>>
>> Something like:
>>
>> dim selectedCol as datagridviewcolumn
>> for each dgvc as datagridviewcolumn in TBL_TimersDataGridView.Columns
>> if dgvc.Name=whatever then

N.b: where "whatever" would be "MyGlobals.TimersSortCol"

>> selectedCol=dgvc
>> exit for
>> end if
>> next
>>

> Thanks for your reply, but I must be missing something - I'm not sure
> how that sorts my column.
>
> Can you provide a little more detail?

You see above where you needed a System.Windows.Forms.DataGridViewColumn
(DGVC) to tell it what to sort on, and you were getting the error that it
couldn't convert from "System.String"? Well, my idea was to find that
particular DGVC given its name (the string).

This part:
> 'Using the Values
> TBL_TimersDataGridView.Sort(MyGlobals.TimersSortCol,
> MyGlobals.TimersSortOrd)

Gave you the error
> Unable to cast object of type 'System.String' to type
> 'System.Windows.Forms.DataGridViewColumn'.

because the first argument must be a DGVC.

Does that fill in the gap I left?

(The comments in your code "returns a number" are a bit unhelpful when it is
actually returning a string.)

Andrew