|
-
May 31st, 2009, 06:06 PM
#1
Thread Starter
Hyperactive Member
DataGridView Custom Properties
I'd like to add some custom properties to the columns of my DataGridView control. I'm not sure how to do it.
I tried this once before but never got it finished. Basically, I'm making a teacher gradebook. Fore each column, I need to add properties called Assignment, DateAssigned, DateDue, PerfectScore, AssignmentType, etc.
Any ideas?
-
May 31st, 2009, 06:15 PM
#2
Re: DataGridView Custom Properties
If you're describing what I think you are then what you want is called Inheritance. There's a lot of inheritance tutorials online if you google for them.
-
May 31st, 2009, 06:46 PM
#3
Re: DataGridView Custom Properties
Those really don't sound like properties that should be added to a DataGridViewColumn because they have nothing to do with displaying data in a DataGridView. They sound like they ARE the data. Can you explain exactly what you are trying to achieve because I'm fairly sure that there's a better way than adding those properties to a DataGridViewColumn.
-
May 31st, 2009, 07:12 PM
#4
Thread Starter
Hyperactive Member
Re: DataGridView Custom Properties
I want to keep the data for each assignment (each column in the DataGridView) with the actual student grades. I don't want to bother with arrays.
I know that I need to create a custom control that inherits the DataGridView but the DataGridView itself is a collection of cell collected into columns, etc.
The whole point is to keep the data in the control, not in arrays. I suppose I could add a few extra hidden rows to the grid and store the data there (and I might do that). But then if I add a new row (a new student) I think it would get added as the last row - then I'd have to move all my info in the hidden rows down one row.
Know what I mean Vern?
-
May 31st, 2009, 07:41 PM
#5
Re: DataGridView Custom Properties
As far as what you're actually asking for, you don't need to change the DataGridView control at all. You simply need to inherit the DataGridViewTextBoxColumn (or some other column type if it's more appropriate) and then declare your properties as you would for any other class. You then add instances of your column type to the grid instead of the usual text box columns.
I still think that this is a bad idea though. You should be defining your own Assignment class and add these properties to that. You can then setup a correspondence between a column and an Assignment using a Dictionary if you like. You say that you don't want to "bother" with arrays but you should do what is proper and if the use of one or more arrays is appropriate then that's what you should be doing.
-
May 31st, 2009, 10:04 PM
#6
Thread Starter
Hyperactive Member
Re: DataGridView Custom Properties
Why would I want to do an Assignment Class and not and Assignment Structure? What's the advantage?
-
May 31st, 2009, 10:39 PM
#7
Re: DataGridView Custom Properties
A structure may well be fine. If the type is small and simple then a structure will do just as well or maybe even better. The general rule is that if an object occupies more than 16 bytes then its type should be a class. Note that this means the object itself, not objects that it might refer to. If an object has a String field then that field occupies 4 bytes, no matter how long the string is. The object contains a reference to the string only.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|