Solved

FORMATTING DATAGRIDVIEW PROBLEM

Posted on 2013-06-18
7
178 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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…

738 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