MSHFlexGrid - Set Column Width, Color, Font and Grid style VB6.0

Whenever we want to show data in list with stylish look then MSHFlexGrid has features to design your table in Vb6.0. There is many coding process to give attractive look to your application. And here SKOTechLearn describe the process to Design MSHFlexGrid with attractive look of .

This control provide the settings to change Column width, Column and Rows Color style , Column and Rows Font style and Grid Style. Set attractive color to columns and design every column with different font and also design attractive Grid style.

First of all, find and add MSHFlexGrid control to Toolbox, For understanding purpose just add some record in this control.

This component provide a stylish look that Listview control cannot provide in VB6.0.

MSHFlexGrid Style:
Take a look of this component.
Image of MSHFlexGrid advance Look
Stylish Look
There is following point of this control's advance features.

  1. Design Text and Cell Style
  2. Column Width setting
  3. Text Alignment setting
  4. Design Background, Font and Grid Color
  5. MSHFlexGrid Font setting in every Column

(1) Design MSHFlexGrid Text and Cell Style:

If you want to design text and column style, this will done through setting on properties or through code.

Text and Cell Style through Properties Settings:
Go to "Properties Window", and find 'GridLines' and select related option which want to apply, this can design rows and cols style except Fixed rows and cols.

After that find 'GridLinesFixed' and select related option. This can design fixed columns and row style.

Note: 'GridLines' and 'GridLinesFixed' will apply the style of Columns and Rows or it can be apply on cell's style.

Database connection in MSHFlexGrid with ADODC

After that find 'TextStyle' and select related option, this will process on Text style except Fixed text. After that find 'TextStyleFixed' and select related option. This can process on fixed text style.

Grid and Text Settings for MshFlexGrid
GridLines and TextStyle Settings

Text and Cell Style through Code:
Write following code on command button. Suppose we drag command button from Toolbox to Form and set its Name as 'Style_Cmd'. Write on its click event as shown bellow.

We will change MSHFlexGrid1's Name as "MGrid1".

Code:
Private Sub Style_Cmd_Click() 
   With MGrid1
     .GridLinesFixed = flexGridInset
     .TextStyleFixed = flexTextRaisedLight 

     .TextStyle = flexTextRaised 
     .GridLines = flexGridRaised 
   End With
End Sub


(2)  MSHFlexGrid Column Width Setting:

Setting up to adjusting column width, just write code for it, there is no option in "Properties Window" to these settings.

Drag command button from Toolbox and set its Name as 'Change_Width_Cmd'. Write on its click event as shown bellow.
Private Sub Change_Width_Cmd_Click() 
   With MGrid1
      .ColWidth(0) = 600 
      .ColWidth(1) = 2300
      .ColWidth(2) = 700 
      .ColWidth(3) = 1500
  End With
End Sub

You have to give col number (like: 0, 1, 2, 3 etc) in 'ColWidth()' property. And give width value in it.


(3) MSHFlexGrid Text Alignment Setting:

Setting up to process on Text alignment of cols or Fixed columns, just write code for it, here is no way to process through "Properties Window". Now come to the event window.

Drag command button and modify its Name as 'Change_Align_Cmd' and write on its Click() event as shown bellow.
Private Sub Change_Align_Cmd_Click() 
   With MGrid1
      'For Fixed column Alignment 
     .ColAlignmentFixed(0) = 3
     .ColAlignmentFixed(1) = 3
 
     'For column Alignment
     .ColAlignment(1) = 3 
     .ColAlignment(2) = 3
   End With
End Sub
Setting alignment through number. The following number describes the alignment adjustment.

0-Justify or Default Alignment
1-Left Alignment
3-Middle Alignment

Item Update, Edit or Delete from MSHFlexGrid.

(4) MSHFlexGrid Background, Font and Grid Color :

If you want to design cols and row's back, Font and Grid color, go to "Properties Window" with following related settings.

Background:
BackColor: This is cell’s back color property.
BackColorBkg: This is background back color property.
BackColorFixed: This is Fixed cell’s back color property.
BackColorSel: This is cell’s selection back color property.
BackColorUnpopulated: This is unpopulated cell’s back color property.

Font:
ForeColor: Cell’s Font color property.
BackColorFixed: Fixed cell’s Font color property.
ForeColorSel: Cell’s selection’s Font color property.

Grid:
GridColor: For cell’s Grid Line
GridColorFixed: For Fixed cell’s Grid Line
GridColorUnpopulated: For changing unpopulated cell’s Grid Line

You can apply this settings through properties window or set back and font color through coding. Drag command button from Toolbox and set its Name as 'Change_Color_Cmd' and write code in its click event as described below.

Color Settings for MSHFlexgrid Style
Color Settings

Private Sub Change_Color_Cmd_Click() 
   With MGrid1
       'For Back color
       .BackColor = &HC0FFFF
       .BackColorBkg = &HFAF1DA
       .BackColorFixed = &HCC93C2
       .BackColorSel = &H808000

       'For Font Color
       .ForeColor = &HC0& 
       .ForeColorFixed = &H400000 
       .ForeColorSel = &HFFFF& 

       'For Grid Line Color
       .GridColor = &HFF00FF
       .GridColorFixed = &HFF0000
       .GridColorUnpopulated = &H80C0FF 
   End With
End Sub

(5) MSHFlexGrid Font Setting in Every Column:

For changing Fixed cols font and Related cols font, process through "Properties Window". But if you process on every column with different font write code for it. Drag command button from Toolbox and modify its Name as 'Change_Font_Cmd' and write code on its click event as shown below.

Private Sub Change_Font_Cmd_Click()
   With MGrid1
        'set font of col 1 and row 1,2,3 etc number
        .Col = 1
        .Row = 1
        .CellFontName = "Calibri"
        .CellFontSize = 11

        .Row = 2
        .CellFontName = "Calibri"
        .CellFontSize = 11
        'set  Font of col 2 and row 1,2,3 etc number
   End With
End Sub

The following image describe above given 5 point.
advance feature for set MSHFlexGrid Style
Output with advance feature
There is the setting of Style through output with different style change.

This is Advance Feature tips to Design Column's width, Color, Font, Grid style in MSHFlexGrid in vb6.0 at runtime (SKOTechLearn).

Column header and Item add in MSHFlexgrid in vb6.0

0 comments: