Solved

FORMATTING DATAGRIDVIEW PROBLEM

Posted on 2013-06-18
7
177 Views
Last Modified: 2013-08-08
Hi All,

I have below code to format dgv, but does not effect at all.
It is pretty obvious from Header Text when the application is running.

 Private Sub Format_Grid_Barang()
 
        Try

            With dgvData

                .DataSource = Me.dtData

                .RowHeadersVisible = False
                .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
                .AutoGenerateColumns = False

                Dim intDisplayIndex As Integer = -1

                .Columns("BarangCode").Visible = False

                .Columns("Qty").HeaderText = "KTS"
                .Columns("Qty").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
                .Columns("Qty").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
                .Columns("Qty").MinimumWidth = 60
                .Columns("Qty").MinimumWidth = ERV_Global.Inc_Number(intDisplayIndex)

                .Columns("Satuan").HeaderText = "SATUAN"
                .Columns("Satuan").MinimumWidth = 60
                .Columns("Satuan").MinimumWidth = ERV_Global.Inc_Number(intDisplayIndex)

                .Columns("FullName").HeaderText = "NAMA BARANG"
                '.Columns("FullName").DefaultCellStyle.WrapMode = DataGridViewTriState.True
                .Columns("FullName").MinimumWidth = 500
                .Columns("FullName").MinimumWidth = ERV_Global.Inc_Number(intDisplayIndex)

                .Columns("HargaSatuan").HeaderText = "@HARGA"
                .Columns("HargaSatuan").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
                .Columns("HargaSatuan").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
                .Columns("HargaSatuan").MinimumWidth = 100
                .Columns("HargaSatuan").MinimumWidth = ERV_Global.Inc_Number(intDisplayIndex)

                .Columns("Diskon").HeaderText = "DISKON"
                .Columns("Diskon").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
                .Columns("Diskon").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
                .Columns("Diskon").MinimumWidth = 100
                .Columns("Diskon").MinimumWidth = ERV_Global.Inc_Number(intDisplayIndex)

                .Columns("Total").HeaderText = "TOTAL"
                .Columns("Total").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
                .Columns("Total").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
                .Columns("Total").MinimumWidth = 100
                .Columns("Total").MinimumWidth = ERV_Global.Inc_Number(intDisplayIndex)

                .Refresh()

            End With

        Catch ex As Exception

        End Try
     
    End Sub

What is wrong ?

Thank you.
0
Comment
Question by:emi_sastra
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 11

Expert Comment

by:Deepak Lakkad
ID: 39258670
Hi

Remove "Refresh" method and try

- Deepak Lakkad
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 39259896
-Remove "Refresh" method and try
Why ?

Thank you.
0
 
LVL 11

Expert Comment

by:Deepak Lakkad
ID: 39261342
Hi,

I have used following code in one of my project.

Private Sub ArrangeDataGridViewColumns()
        ' Set Data Source
        dgvItemCategory.DataSource = dtItemCategory

        ' Set Column Heading ...
        dgvItemCategory.Columns(0).HeaderText = "Sr #"
        dgvItemCategory.Columns(1).HeaderText = "Item Category"
        dgvItemCategory.Columns(2).HeaderText = "Item Group"
        dgvItemCategory.Columns(3).HeaderText = "CatgID"
        dgvItemCategory.Columns(4).HeaderText = "GroupID"

        ' Hide Columns ...
        dgvItemCategory.Columns(3).Visible = False
        dgvItemCategory.Columns(4).Visible = False

        'Right Alignment
        dgvItemCategory.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
    End Sub

Open in new window


It is working for me ...

Refresh Method redraws the control ... so I think Refresh method is not required

- Deepak Lakkad
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:emi_sastra
ID: 39261364
I know the problem :

Dim intDisplayIndex As Integer = -1

     .Columns("Qty").MinimumWidth = ERV_Global.Inc_Number(intDisplayIndex)

intDisplayIndex = 0

 Public Shared Function Inc_Number(ByRef intNumber As Integer) As Integer
        intNumber += 1
        Inc_Number = intNumber
    End Function

Should be :

   .Columns("Qty").DisplayIndex= ERV_Global.Inc_Number(intDisplayIndex)

Thank you.
0
 
LVL 11

Expert Comment

by:Deepak Lakkad
ID: 39261380
ok, then what's the problem?
0
 
LVL 1

Accepted Solution

by:
emi_sastra earned 0 total points
ID: 39261410
Dim intDisplayIndex As Integer = -1

     .Columns("Qty").MinimumWidth = ERV_Global.Inc_Number(intDisplayIndex)

After ERV_Global.Inc_Number(intDisplayIndex) then intDisplayIndex = 0

.Columns("Qty").MinimumWidth = ERV_Global.Inc_Number(intDisplayIndex)
MinimumWidth  can not be 0

After I change to :

   .Columns("Qty").DisplayIndex= ERV_Global.Inc_Number(intDisplayIndex)

then the problem is gone.

Thank you.
0
 
LVL 1

Author Closing Comment

by:emi_sastra
ID: 39392167
The problem is solved by my self.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question