Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Data Grid - Free Grid Control

0.00/5 (No votes)
20 Oct 2007 1  
The best free grid control, you can choose any format (font name, bold, italic...) for each field and much more
Screenshot - vb_datagrid.jpg

Introduction

This is the best free grid control for VB 6. With this control, you can format each field (set font name, bold, italic, underline, align), it's very easy to use. Support AddRow and AddColumn. You can also auto add new row if you accessed to last row. Events (click, change...) give you indexes of last and new column/row. There are many properties, so you can easily create designs as per your wish (fore color, fore color selected, grid color, grid color fixed, back color, back color selected, back color fixed...).

There is also a property called RowFixedData where you can choose what will be printed in rowname field (its first column). You can choose between:

  • UserDefined – show text defined by programmer
  • RowNumber – auto generate row numbers and show them
  • SelectedPointer – Show * at selected row

Example Codes

' Setting row / column count:
Me.ucGrid1.Cols = 5
Me.ucGrid1.Rows = 1
' Set row / column names – if first index is 0 then you change column names, 
' if second index is 0 then you change row names:
Me.ucGrid1.Data(0, 1) = "ID"
Me.ucGrid1.Data(0, 2) = "Name"
Me.ucGrid1.Data(0, 3) = "Phone"

How to Use

This is a standard EXE project. If you want to add this to your project, you must copy all modules and user controls to your project directory. After that, you must add these files to your project.

If you want, you can create an ActiveX project and add this file to this project and create OCX.

Properties

  • AutoAddNextRow As Boolean – if True then control will automatically add new row when you access the last row
  • BackColor As OLE_COLOR – data back color
  • BackColorFixed As OLE_COLOR – row / column names back color
  • BackColorContainer As OLE_COLOR – user control back color
  • BackColorSelected As OLE_COLOR – selected field back color
  • Cols As Long – number of columns, when changed all data are deleted
  • Rows As Long – number of rows, when changed all data are deleted
  • Data(ByVal s_row As Long, ByVal s_col As Long) As String – data in selected field
  • Editable As Boolean – if True user can edit fields
  • FldAlign(ByVal mRow As Long, ByVal mCol As Long) As eAlign – (Left, Center or Right) field text (data) align
  • FldFontBold(ByVal mRow As Long, ByVal mCol As Long) As Boolean – field font bold
  • FldFontItalic(ByVal mRow As Long, ByVal mCol As Long) As Boolean – field font italic
  • FldFontName(ByVal mRow As Long, ByVal mCol As Long) As String – field font name
  • FldFontUnderline(ByVal mRow As Long, ByVal mCol As Long) As Boolean – field font underline
  • ForeColor As OLE_COLOR – data fore color
  • ForeColorFixed As OLE_COLOR – row / column name fore color
  • ForeColorSelected As OLE_COLOR – selected field fore color
  • GridColor As OLE_COLOR – grid color (where is data)
  • GridColorFixed As OLE_COLOR – grid color (where is row / col names)
  • SelectedCol As Long – return / set selected column
  • SelectedRow As Long – return / set selected row
  • Sizable As Boolean – if True, user can change field width / height

History

  • 20th October, 2007: Initial post

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here