Solved

FORMATTING DATAGRIDVIEW PROBLEM

Posted on 2013-06-18
7
175 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

785 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