Click here to Skip to main content
6,636,867 members and growing! (20,285 online)
Email Password   helpLost your password?
Desktop Development » Miscellaneous » General     Advanced License: The Code Project Open License (CPOL)

Generic DataGridView V2.0

By Yildirim Kocdag

A Generic DataGridView which has features of DataGridViewComboBoxColumn, DataGridViewCalendarColumn, DataGridViewMaskedTextBoxColumn, Validating DataGridView Columns and Saving any edited row with automatic created queries.
C#, Windows, .NET, Visual Studio, Dev
Version:2 (See All)
Posted:4 Jul 2006
Updated:24 Jan 2008
Views:203,166
Bookmarked:174 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
35 votes for this article.
Popularity: 6.35 Rating: 4.11 out of 5
3 votes, 8.6%
1

2
1 vote, 2.9%
3
6 votes, 17.1%
4
25 votes, 71.4%
5
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)

About the Author

Yildirim Kocdag


Member
Yildirim Kocdag is a MSc.BSc.Computer Engineer from Istanbul. He is working as a .NET consultant. Currently using c#, vb.net, asp.net, javascript, SQL and Oracle. His Favourite areas in Computer Science are Compilers, Expert Systems, Digital Image Processing, AI and Extreme Programming.
ykocdag@yahoo.com

Occupation: Web Developer
Location: Turkey Turkey

Other popular Miscellaneous articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 76 (Total in Forum: 76) (Refresh)FirstPrevNext
GeneralHow to add the control to the Visual Studio 2005 Toolbox? PinmemberTomIn0182112:32 15 Jan '09  
GeneralInner join Three Tables Pinmemberu2envy1223:30 18 Dec '08  
GeneralCant get project to open Pinmemberu2envy1223:07 18 Dec '08  
Generalhow to stop tab key navigation PinmemberVenhKates0:45 19 Sep '08  
Questionnested grid PinmemberDailyCoding4:02 3 Jul '08  
Generalprivate void Row_Save(int rowNumber) not working PinmemberDekkie10:40 27 May '08  
GeneralRe: private void Row_Save(int rowNumber) not working PinmemberYildirim Kocdag21:15 27 May '08  
GeneralRe: private void Row_Save(int rowNumber) not working PinmemberDekkie23:16 28 May '08  
GeneralRe: private void Row_Save(int rowNumber) not working [modified] PinmemberDekkie23:27 28 May '08  
GeneralGood idea, but not useful at all PinmemberJ.Thomas1:45 19 Apr '08  
GeneralRe: Good idea, but not useful at all PinmemberYildirim Kocdag3:25 19 Apr '08  
Generalmerhaba Pinmemberdexter344:14 17 Apr '08  
GeneralRe: merhaba PinmemberYildirim Kocdag3:27 19 Apr '08  
Generalwhat is the purpose of bool blank control in addvalidation PinmemberMathewJ1:39 9 Apr '08  
GeneralRe: what is the purpose of bool blank control in addvalidation PinmemberYildirim Kocdag1:54 9 Apr '08  
GeneralHow to Add Validation as column property @ designtime? PinmemberMathewJ3:02 3 Apr '08  
GeneralRe: How to Add Validation as column property @ designtime? PinmemberYildirim Kocdag3:10 3 Apr '08  
GeneralRe: How to Add Validation as column property @ designtime? PinmemberMathewJ21:53 3 Apr '08  
GeneralRe: How to Add Validation as column property @ designtime? PinmemberYildirim Kocdag23:28 3 Apr '08  
GeneralAdding Calendar Cell to new rows PinmemberMathewJ2:27 2 Apr '08  
GeneralRe: Adding Calendar Cell to new rows PinmemberYildirim Kocdag4:45 2 Apr '08  
GeneralRe: Adding Calendar Cell to new rows PinmemberMathewJ19:08 2 Apr '08  
GeneralBug in Mask PinmemberMedo19912:45 24 Feb '08  
GeneralRe: Bug in Mask PinmemberYildirim Kocdag22:08 24 Feb '08  
GeneralRe: Bug in Mask PinmemberMedo1994:49 25 Feb '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 24 Jan 2008
Editor: Deeksha Shenoy
Copyright 2006 by Yildirim Kocdag
Everything else Copyright © CodeProject, 1999-2009
Web22 | Advertise on the Code Project