-
Jan 26th, 2015, 01:58 PM
#1
Thread Starter
Fanatic Member
DataGridView bound to a Datatable question...
Hi all.
I'm just discovering the joys of binding a DataTable to a DataGridView. Now I'm a bit disapointed as I was hoping that the editing control for each cell would correspong a bit better to the column datatype of the datatable. For boolean values, it works fine, as cells are automatically checkbox cells. But for all other datatypes that would naturally use a specific editing control other then the default textbox control (like a numerical up/down for integers, a date time picker for date, etc.), nothing. Just plain old textbox control. So if the user enters a non numerical value in a numerical field, boom!
Was I naive in thinking it would be more automated? Or is there something I should have set that I didn't prior to binding my DataGridView to the DataTable?
Thanks in advance!
Last edited by Alain; Jan 26th, 2015 at 05:57 PM.
Don't ask why, just reboot!
-
Jan 26th, 2015, 06:30 PM
#2
Re: DataGridView bound to a Datatable question...
Warning: You hit upon one of my pet peeves.
It is named a DataGridView. The documentation states:Yes, it also facilitates data entry, but its main purpose is to display data. As the description states, the grid is customizable and various prebuilt column types are available for you to select from. If the prebuilt types do not meet your needs, you can code a column that does.
You do not like the fact that default column selection for most types is a DataGridViewTextBoxColumn. Realistically, what should the developer have chosen considering that a textual representation is the most common form of displaying values? You say a DateTimePicker should be used for date types, but I could say that it should have been plain text (as it is) or perhaps display a Calendar. Who is the poor designer of a relatively customizable control to please with their selection of defaults?
You say that numeric types should default to a NumericUpDown control. Why? Because some said that that is the control that should be used for numeric value entry? I prefer to use my own control that provides features that I find useful such built-in range checking,but here I am writing about data entry choices for a control that was designed to display (View) data.
The .Net Framework provides many prebuilt tools for you to use and it simplifies things greatly. However, it also allows a developer to expand on the functionality of those existing tools without having to create everything from scratch. It is that ease of expansion that I find to be its greatest feature. If you don't like the way something works, you are free to override the base functionality of many of the classes. In some cases you have to inherit from a low level class to create what you want, but very seldom do you need recreate the wheel to get what you want.
Yes it would be nice if there were more choices built into Visual Studio, but it is impossible to please every one and sometimes you actually have to write code.
Ok, my boiler pressure is returning to its safe level again and I will finish off with directing you to this article: DataGridView Custom Column Sample
P.S.: A probable reason why there is no prebuilt DataTimePicker Column is that it would need to handle null values. This is something that the 'standard' DTP does not like.
-
Jan 26th, 2015, 07:11 PM
#3
Re: DataGridView bound to a Datatable question...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 26th, 2015, 08:51 PM
#4
Thread Starter
Fanatic Member
Re: DataGridView bound to a Datatable question...
Well, sorry if I pressed on your bad button, TnTimMN.
I understand your point. But please know that my request was not motivated by coding laziness. It's more that the current DGV puts one so much 'right in the middle' of a full editing grid that I just thought I missed something while setting it up. I worked a lot with the MSFlexGrid on VB6, and THAT was a truly only viewing grid. The damn thing did nothing else. The DGV, on the contrary, allows for all sorts of editing possility out of the box: user can add new rows, user can edit cells - even if it's by default a textbox control,although boolean values get checkboxes by default. So you got to admit it's a bit misleading for a control that's suppose to just allow to view data.
And, to my defense, if you are that annoyed about such a question, wouldn't part of it be probably because it keeps poping up quite frequently? Meaning we might be a bunch asking ourselves the same question? Don't forget a considerable number of C++ old schooler used to think clicking a dragging a button on a form was lame, and if we wanted buttons on our forms, than we should just code it out like grown ups do and stop whinning.
I'm pretty sure if some grid would behave exactly like MS Access does, just by binding a table to that said grid, many people would be quite happy to use it. I know I would.
That said, I will gladly customise the columns on my grid. Hey, I like to code afterall!
Thanks for the links guys!
Cheers,
Last edited by Alain; Jan 26th, 2015 at 10:46 PM.
Don't ask why, just reboot!
-
Jan 26th, 2015, 10:48 PM
#5
Re: DataGridView bound to a Datatable question...
-
Jan 26th, 2015, 11:07 PM
#6
Thread Starter
Fanatic Member
Re: DataGridView bound to a Datatable question...
I understand. No worries. It's healthy to blow steam off once in a while. I'm glad I could help you do that!
Don't ask why, just reboot!
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
|