Solved

FORMATTING DATAGRIDVIEW PROBLEM

Posted on 2013-06-18
7
174 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now