Click here to Skip to main content
11,640,866 members (62,894 online)
Click here to Skip to main content

Generic DataGridView V2.0

, 24 Jan 2008 CPOL 395.2K 14.6K 253
Rate this:
Please Sign up or sign in to vote.
A Generic DataGridView which has features of DataGridViewComboBoxColumn, DataGridViewCalendarColumn, DataGridViewMaskedTextBoxColumn, Validating DataGridView Columns and Saving any edited row with automatic created queries.
Sample Image - form2.jpg

Introduction

GenericDataGridView is a new control which is more flexible for coding than a simple datagrid. However, there are a lot of developers who are facing difficulties about DataGridView Calendar, Mask, ComboBox and also Validations. Actually, GenericDataGridView does not support such important properties.

Generic Data Grid View is a user control which can be really helpful for:

  1. Adding a combobox to DataGridView (DataGridViewComboBoxColumn)
  2. Adding a calendar to DataGridView (DataGridViewCalendarColumn)
  3. Adding a MaskedTextBox to DataGridView (DataGridView MaskedTextBox column)
  4. Validating DataGridView columns
  5. Saving any edited row with automatic created queries.

While I was coding Generic DataGridView, I tried to put all important features which can be required for a project. However, these are unlimited. You can add more properties and methods in order to improve it.

After placing the GenericDataGridView(GDGV) in your project, you should set some properties.

Picture 1 - Properties

DataColumns should be set in design time or in Form_Load such as above and below:

GenericDataGridView1.DataColumns = "OrderID,CustomerID%,OrderDate%,
	EmployeeID,Freight, ShipPostalCode%"

The column which has a string or date type should be written with % to distinguish. It is necessary for creating DML (Save and Update Queries). And also the first column should be an identity column. The Northwind Database and the Orders table has been selected to demonstrate the example project. In addition to this, the first column (OrderID) must be an identity column.

GenericDataGridView1.DataConnection = "Integrated Security=SSPI;
Persist Security Info=False;Initial Catalog=Northwind;Data Source=localhost"
GenericDataGridView1.DataColumnsTable = "Orders"

There are some other definitions to be set in form_load:

  • FillAll: to fill DataGridView
  • AddCombo: to add a comboboxcolumn to DataGridView
  • AddValidation: to add validation to Columns
  • AddMask: to place a mask to columns
  • AddCalendar: to add a calendarcolumn to DataGridView

Picture 2 - Form Load

<
Picture 3 - Add Combo

Picture 4 - Add Validation

Picture 5 - Add Calendar

Picture 6 - Add Mask

Picture 7 - Form Load

Picture 8 - Calendar Column

Picture 9 - Combo Column

Picture 10 - Validation

Picture 11 - MaskedText Column

Picture 12 - Row Saved

P.S.: There can be some bugs related with the properties of the database server and regional settings of the client such as datetime and (, or .) which can be fixed easily. Please feel free to ask any questions. The source code of the project has GenericDataGridView Control (C#), VB.NET Project to demonstrate the control and C# project to demonstrate the control.

Bug Fix Version

Firstly, thanks for your nice contributions. It was almost year ago that I posted the article, now the hit is 70.000. Every day I am receiving new emails with questions and comments from all over the world. I have already fixed some bugs of this version, I am sending a new post with a delay of 3 months.

The bug fix version includes 2 points:

  1. Null Column problem of dates, via adding datecolumns such as "OrderDate-" to DataColumns property of GDGV (GenericDataGridView). This problem is going to be solved. You will find one example in the source code.
  2. DateFormat problem, every country has got regional settings and database settings, that is why the new property "DBDateFormat" is defined. You can simply add it.
GenericDataGridView1.DBDateFormat = "MM/dd/yyyy"

You will find one example in the source code.

Dear Readers,

I hope you will accept my excuses for delay of bug fix because of new component work. I have started to work on a new component which is GenericWebDataGrid control. As you know, web components are getting more attention after the client side programming has become popular. My new toy is working also on the client side. It is fast for updates and inserts (database works) and it is fast for development. I hope I will publish it by the end of this year. It is going to be free and open source.

The GenericWebDataGrid was published. Please check my other articles.

Please don't hesitate to ask any questions anytime. You can email me at ykocdag80@yahoo.com.

License

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

Share

About the Author

Yildirim Kocdag
Architect
Turkey Turkey
Phd. Yildirim Kocdag is a Computer Engineer.

Programming Languages
Android, Objective-c, c#, vb.net, asp.net, javascript, TSQL.

Computer Science
DataMining, Compilers, Expert Systems, Digital Image Processing, AI and Extreme Programming.

ykocdag@yahoo.com

http://www.linkedin.com/profile/view?id=223886830

You may also be interested in...

Comments and Discussions

 
QuestionBir Kaç Soru Pin
ssomar15-Jan-14 4:53
memberssomar15-Jan-14 4:53 
AnswerRe: Bir Kaç Soru Pin
Yildirim Kocdag17-Jan-14 0:26
memberYildirim Kocdag17-Jan-14 0:26 
GeneralRe: Bir Kaç Soru Pin
ssomar17-Jan-14 2:21
memberssomar17-Jan-14 2:21 
GeneralRe: Bir Kaç Soru Pin
Yildirim Kocdag17-Jan-14 9:37
memberYildirim Kocdag17-Jan-14 9:37 
GeneralRe: Bir Kaç Soru Pin
ssomar17-Jan-14 23:24
memberssomar17-Jan-14 23:24 
GeneralRe: Bir Kaç Soru Pin
Yildirim Kocdag20-Jan-14 1:10
memberYildirim Kocdag20-Jan-14 1:10 
GeneralRe: Bir Kaç Soru Pin
ssomar20-Jan-14 1:30
memberssomar20-Jan-14 1:30 
GeneralThanks! Pin
Member 1023516027-Aug-13 2:56
memberMember 1023516027-Aug-13 2:56 
GeneralRe: Thanks! Pin
Yildirim Kocdag28-Aug-13 4:51
professionalYildirim Kocdag28-Aug-13 4:51 
GeneralRe: Thanks! Pin
Vígolfr Kolskeggr30-Aug-13 2:57
professionalVígolfr Kolskeggr30-Aug-13 2:57 
GeneralRe: Thanks! Pin
Yildirim Kocdag1-Sep-13 1:03
professionalYildirim Kocdag1-Sep-13 1:03 
GeneralMy vote of 5 Pin
ProEnggSoft7-Mar-12 2:07
memberProEnggSoft7-Mar-12 2:07 
GeneralRe: My vote of 5 Pin
Yildirim Kocdag8-Mar-12 23:27
memberYildirim Kocdag8-Mar-12 23:27 
GeneralMy vote of 5 Pin
manoj kumar choubey7-Feb-12 0:15
membermanoj kumar choubey7-Feb-12 0:15 
GeneralRe: My vote of 5 Pin
Yildirim Kocdag8-Mar-12 23:26
memberYildirim Kocdag8-Mar-12 23:26 
GeneralTo load the grid Pin
gito6922-Nov-10 11:02
membergito6922-Nov-10 11:02 
QuestionData Grid Date dd-mm-yyyy. instead mm/dd/yyy Pin
vishaldsh6-Jul-10 19:47
membervishaldsh6-Jul-10 19:47 
GeneralMy vote of 1 Pin
khurram sheharyar31-Jan-10 7:36
memberkhurram sheharyar31-Jan-10 7:36 
GeneralMy vote of 2 Pin
chetanRock17-Dec-09 22:34
memberchetanRock17-Dec-09 22:34 
QuestionHow to add the control to the Visual Studio 2005 Toolbox? Pin
TomIn0182115-Jan-09 11:32
memberTomIn0182115-Jan-09 11:32 
GeneralInner join Three Tables Pin
u2envy1218-Dec-08 22:30
memberu2envy1218-Dec-08 22:30 
GeneralCant get project to open Pin
u2envy1218-Dec-08 22:07
memberu2envy1218-Dec-08 22:07 
Questionhow to stop tab key navigation Pin
VenhKates18-Sep-08 23:45
memberVenhKates18-Sep-08 23:45 
Questionnested grid Pin
DailyCoding3-Jul-08 3:02
memberDailyCoding3-Jul-08 3:02 
Generalprivate void Row_Save(int rowNumber) not working Pin
Dekkie27-May-08 9:40
memberDekkie27-May-08 9:40 
GeneralRe: private void Row_Save(int rowNumber) not working Pin
Yildirim Kocdag27-May-08 20:15
memberYildirim Kocdag27-May-08 20:15 
GeneralRe: private void Row_Save(int rowNumber) not working Pin
Dekkie28-May-08 22:16
memberDekkie28-May-08 22:16 
GeneralRe: private void Row_Save(int rowNumber) not working [modified] Pin
Dekkie28-May-08 22:27
memberDekkie28-May-08 22:27 
GeneralGood idea, but not useful at all Pin
J.Thomas19-Apr-08 0:45
memberJ.Thomas19-Apr-08 0:45 
GeneralRe: Good idea, but not useful at all Pin
Yildirim Kocdag19-Apr-08 2:25
memberYildirim Kocdag19-Apr-08 2:25 
Generalmerhaba Pin
dexter3417-Apr-08 3:14
memberdexter3417-Apr-08 3:14 
GeneralRe: merhaba Pin
Yildirim Kocdag19-Apr-08 2:27
memberYildirim Kocdag19-Apr-08 2:27 
Questionwhat is the purpose of bool blank control in addvalidation Pin
MathewJ9-Apr-08 0:39
memberMathewJ9-Apr-08 0:39 
AnswerRe: what is the purpose of bool blank control in addvalidation Pin
Yildirim Kocdag9-Apr-08 0:54
memberYildirim Kocdag9-Apr-08 0:54 
QuestionHow to Add Validation as column property @ designtime? Pin
MathewJ3-Apr-08 2:02
memberMathewJ3-Apr-08 2:02 
AnswerRe: How to Add Validation as column property @ designtime? Pin
Yildirim Kocdag3-Apr-08 2:10
memberYildirim Kocdag3-Apr-08 2:10 
GeneralRe: How to Add Validation as column property @ designtime? Pin
MathewJ3-Apr-08 20:53
memberMathewJ3-Apr-08 20:53 
GeneralRe: How to Add Validation as column property @ designtime? Pin
Yildirim Kocdag3-Apr-08 22:28
memberYildirim Kocdag3-Apr-08 22:28 
GeneralAdding Calendar Cell to new rows Pin
MathewJ2-Apr-08 1:27
memberMathewJ2-Apr-08 1:27 
GeneralRe: Adding Calendar Cell to new rows Pin
Yildirim Kocdag2-Apr-08 3:45
memberYildirim Kocdag2-Apr-08 3:45 
GeneralRe: Adding Calendar Cell to new rows Pin
MathewJ2-Apr-08 18:08
memberMathewJ2-Apr-08 18:08 
GeneralBug in Mask Pin
Medo19924-Feb-08 11:45
memberMedo19924-Feb-08 11:45 
GeneralRe: Bug in Mask Pin
Yildirim Kocdag24-Feb-08 21:08
memberYildirim Kocdag24-Feb-08 21:08 
GeneralRe: Bug in Mask Pin
Medo19925-Feb-08 3:49
memberMedo19925-Feb-08 3:49 
GeneralRe: Bug in Mask [modified] Pin
J.Thomas19-Apr-08 0:19
memberJ.Thomas19-Apr-08 0:19 
GeneralReally a helpful code Pin
Neogerot28-Nov-07 0:50
memberNeogerot28-Nov-07 0:50 
GeneralEmpty Date and Localization Pin
qumer10119-Oct-07 12:17
memberqumer10119-Oct-07 12:17 
GeneralControl stops responding Pin
rctaubert4-Oct-07 2:58
memberrctaubert4-Oct-07 2:58 
GeneralRe: Control stops responding Pin
Yildirim Kocdag5-Oct-07 3:43
memberYildirim Kocdag5-Oct-07 3:43 
GeneralRe: Control stops responding Pin
rctaubert5-Oct-07 5:47
memberrctaubert5-Oct-07 5:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150731.1 | Last Updated 24 Jan 2008
Article Copyright 2006 by Yildirim Kocdag
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid