vb.net windows forms - datagrid - left tab - hide

in vb.net windows forms

I would like to use the datagrid just for display purpose.( no insertion or modificaiton or deletion).  

I don't want the datagrid to display a left tab ( > and * will be there to indicate the current row and new row ) before my first column.

give me a suggestion to supress this.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If I'm not mistaken you should set the DataGrid's property

RowHeadersVisible to false

DataGrid dg;
// Code

dg.RowHeadersVisible = false;

Hope this helps


To eliminate the "Add new record" row that's inserted by default, set the ReadOnly property of the Datagrid to True.

myDataGrid.ReadOnly = True

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
or use a list view ... its a great alternative to datagrids when you only want to display the data and disallow editing.
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.


Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()

        'This call is required by the Windows Form Designer.

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
            End If
        End If
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents ListView1 As System.Windows.Forms.ListView
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents ContextMenu1 As System.Windows.Forms.ContextMenu
    Friend WithEvents mnuDetails As System.Windows.Forms.MenuItem
    Friend WithEvents mnuList As System.Windows.Forms.MenuItem
    Friend WithEvents mnuSmall As System.Windows.Forms.MenuItem
    Friend WithEvents mnuLarge As System.Windows.Forms.MenuItem
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.ListView1 = New System.Windows.Forms.ListView
        Me.ContextMenu1 = New System.Windows.Forms.ContextMenu
        Me.mnuDetails = New System.Windows.Forms.MenuItem
        Me.mnuList = New System.Windows.Forms.MenuItem
        Me.mnuSmall = New System.Windows.Forms.MenuItem
        Me.mnuLarge = New System.Windows.Forms.MenuItem
        Me.Label1 = New System.Windows.Forms.Label
        Me.ListView1.AllowColumnReorder = True
        Me.ListView1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.ListView1.ContextMenu = Me.ContextMenu1
        Me.ListView1.FullRowSelect = True
        Me.ListView1.GridLines = True
        Me.ListView1.HideSelection = False
        Me.ListView1.HoverSelection = True
        Me.ListView1.Location = New System.Drawing.Point(16, 16)
        Me.ListView1.Name = "ListView1"
        Me.ListView1.Size = New System.Drawing.Size(456, 168)
        Me.ListView1.TabIndex = 0
        Me.ListView1.View = System.Windows.Forms.View.Details
        Me.ContextMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuDetails, Me.mnuList, Me.mnuSmall, Me.mnuLarge})
        Me.mnuDetails.Index = 0
        Me.mnuDetails.Text = "Details"
        Me.mnuList.Index = 1
        Me.mnuList.Text = "List"
        Me.mnuSmall.Index = 2
        Me.mnuSmall.Text = "Small Icons"
        Me.mnuLarge.Index = 3
        Me.mnuLarge.Text = "Large Icons"
        Me.Label1.Location = New System.Drawing.Point(24, 200)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(392, 72)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "Right click on the list view for options ... ; you can color code the back and fo" & _
        "re colors; you can change the view types to ""detail"", ""list"", ""large/small icons" & _
        """; re-order columns; sort columns ... etc"
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(496, 310)
        Me.Name = "Form1"
        Me.Text = "Form1"

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ds As New DataSet("Data")
        Dim dt As New DataTable("Employees")
        dt.Columns.Add("FirstName", "".GetType)
        dt.Columns.Add("LastName", "".GetType)
        dt.Columns.Add("Salary", (1.1).GetType)
        Dim dr As DataRow
        With dt
            dr = dt.NewRow
            dr("FirstName") = "John"
            dr("LastName") = "Johnson"
            dr("Salary") = 20000

            dr = dt.NewRow
            dr("FirstName") = "Mark"
            dr("LastName") = "Markson"
            dr("Salary") = 30000

            dr = dt.NewRow
            dr("FirstName") = "Lacy"
            dr("LastName") = "Braynt"
            dr("Salary") = 40000

            dr = dt.NewRow
            dr("FirstName") = "Kobe"
            dr("LastName") = "Oneill"
            dr("Salary") = 15000

            dr = dt.NewRow
            dr("FirstName") = "Bill"
            dr("LastName") = "Bush"
            dr("Salary") = 60000

            dr = dt.NewRow
            dr("FirstName") = "George"
            dr("LastName") = "Clinton"
            dr("Salary") = 10000
        End With

        With Me.ListView1
            With .Columns
                .Add("First Name", Me.ListView1.Width / 3, HorizontalAlignment.Right)
                .Add("Last Name", Me.ListView1.Width / 3, HorizontalAlignment.Right)
                .Add("Salary", Me.ListView1.Width / 3, HorizontalAlignment.Right)
            End With
        End With

        Dim ili As New ListViewItem
        For Each dr In ds.Tables(0).Rows
            ili = New ListViewItem(New String() {dr(0), dr(1), Format(dr(2), "currency")})
            ili.BackColor = IIf(dr(2) <= 20000, Color.Gray, Color.White)
            ili.ForeColor = IIf(dr(2) >= 40000, Color.Green, Color.Black)
    End Sub

    Private Sub mnuDetails_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuDetails.Click
        Me.ListView1.View = View.Details
    End Sub

    Private Sub mnuList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuList.Click
        Me.ListView1.View = View.List
    End Sub

    Private Sub mnuSmall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSmall.Click
        MsgBox("you must first attach pictures -- images to list view for this option to be enabled")
        Exit Sub
        Me.ListView1.View = View.SmallIcon
    End Sub

    Private Sub mnuLarge_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuLarge.Click
        MsgBox("you must first attach pictures -- images to list view for this option to be enabled")
        Exit Sub
        Me.ListView1.View = View.LargeIcon
    End Sub
End Class
Bob LearnedCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Split: krznpsk {http:#9913102} & malharone {http:#9914480}

Please leave any comments here within the next seven days.

EE Cleanup Volunteer
RameshKannaAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.