Click here to Skip to main content
13,201,050 members (55,929 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I need some assistance - it's been a while since I've written code, and as such I quickly got lost in it.

I have a question:

I have a form with a gridView, the gridView contains information from a table called Orders. Each record is of type Order.

I then have a static int method that is used to return the information contained in the last of the records of the table, inside a given column.

The call to this method is made using parameter of type Type and one a string - the field name from where the information is to be retrieved.

So how should i proceed? I know a bunch of ways, but not any way in which to do this that doesn't include changing the way the method is called (or parameter types), or turning the method from static to non-static.
Posted 24-Jan-13 3:47am
Kishor Deshpande 24-Jan-13 10:01am
Can you show me your method?
galextudor 24-Jan-13 16:07pm
I can show you how the call to it looks like

private void getEntry(object sender, DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs e)
myRec rec = (myRec)gridView1.GetRow(e.RowHandle); = LastEntry(typeof(myRec), "currentNo") + 1;
Sergey Alexandrovich Kryukov 24-Jan-13 14:36pm
Why, why static method? And do you know what is a static method in fact?
galextudor 24-Jan-13 16:01pm
:)) Yes, I know what a static method is..but it's something like this: I can't change it - it's stupid, dumb and so on, but I can't change it..
Sergey Alexandrovich Kryukov 24-Jan-13 16:10pm
OK, but anyway you should provide more information; I cannot see a problem right now.

The real problem is not that the method is formally static, as you can always pass additional parameter to it to make it behave exactly like and instance one. From your words, I guess you cannot even change its signature, and then it's a real problem. If parameter information is not enough, you might need to add exchange through a shared static field/property, which would resolve the parameter passing problem but add even more stupidity and dumbness to resulting code...

galextudor 24-Jan-13 16:09pm
any help appreciated.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

There is no proper way to do this: because the method is static, it has no access to any of the form instance variables - and the GridView is a form instance object. So unless the GridView or a GridViewRow is passed through as a parameter, there is no "nice" way to do this.

There a way - but it is extremely bad practice, liable to cause you intermittent problems and definitely not recommended in any way, shape or form.

However if for whatever stupid (and it is stupid, trust me) reason you can't change the method to non-static or alter the parameters, you can create a static GridView variable and copy your GridView into that at a suitable point in your program. Your static method can then retrieve it, because it is no longer an instance member of your form class.

But I would prefer to eat my own ears than do it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171020.1 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100