Solved

FORMATTING DATAGRIDVIEW PROBLEM

Posted on 2013-06-18
7
173 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

11 Experts available now in Live!

Get 1:1 Help Now