question

ImadAlmuzain-0432 avatar image
0 Votes"
ImadAlmuzain-0432 asked ImadAlmuzain-0432 commented

DataGridView Column Type Property

Hello
On following document show how to define the DataGridView Column Type, and define calendar column,

https://docs.microsoft.com/en-us/dotnet/desktop/winforms/controls/how-to-host-controls-in-windows-forms-datagridview-cells?view=netframeworkdesktop-4.8&redirectedfrom=MSDN#compiling-the-code

Could please help, after that how to show the "CalendarColumn" type to appear in the Column types list of DataGridview column types to choose it where required, as shown on following photo

87796-dd.jpg


vs-generaldotnet-visual-basic
dd.jpg (86.9 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

removed azure tag

0 Votes 0 ·

Is it a Forms project that is based on .NET Framework (not Core) and what kind of data source are you using for this grid?

0 Votes 0 ·
karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered

I have a code sample for this in C# but not VB .NET.

See Windows forms DataGridView dates and numeric columns (C#) article and source code for using in C#.

Here is a starter project on GitHub.
87790-f1.png

87861-c1.png



f1.png (8.5 KiB)
c1.png (51.1 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ImadAlmuzain-0432 avatar image
0 Votes"
ImadAlmuzain-0432 answered ImadAlmuzain-0432 commented

many thanks karenpayneoregon for reply,

one question only, when I have the CalendarColumn Class added to project,
what else should do to let Calendar Column type appear in the list,?

thanks

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

  • The screenshot shows how to add the column

  • Once added, select the property window for the column, set the DataPropertyName (this is the field name in a DataTable or a property name from a container/class)

  • Set the DataSource of the DataGridView to the DataTable or List that has the value set in DataPropertyName above.

The above although done in the designer can be done in code while doing this in code has no value per-say.

Lastly, when you say list surely you mean the DataGridView as a list may or may not be the DataSource of the DataGridView and if using a list that means the DataGridView is not sortable and should use a BindingSource linked to a BindingList where the BindingSource becomes the DataSource of the DataGridView.


0 Votes 0 ·

Hello

This is screen shot,

all column types are there but no "Calendar Column" !!

this what I mean in "list", list of types like textbox, checkbox, combobox ..etc.. but not show the "CalendarColumn" which suppose to be read from the class was added

Its shown in your screen shot but not appear with me..

thanks

87911-hh.jpg


0 Votes 0 ·
hh.jpg (84.2 KiB)

After adding the CalendarColumn to the project you then need to build the project before the CalendarColumn will appear in the list of columns. So before build it will not show in the list or in the toolbox, after building it will show in the list and toolbox.
87903-f1.png


0 Votes 0 ·
f1.png (6.3 KiB)

Thanks a lot karenpayneoregon for help..

it was solved by changing the "Target CPU" to "AnyCPU" on Compile tab,,
I was selected 64,

much appreciated

87748-jjj.jpg


0 Votes 0 ·
jjj.jpg (53.4 KiB)
karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered karenpayneoregon edited

Here is a full code sample, took about 10 minutes to write. To run requires a SQL-Server database (I don't have another database e.g. MS-Access, Oracle, MySql ready)

  • In the repository run this data script in SSMS (SQL-Server Management Studio)

  • Build

  • Run



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.