Solved

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

Posted on 2003-12-10
7
386 Views
Last Modified: 2008-02-01
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.

regards,
Rameshkanna
0
Comment
Question by:RameshKanna
7 Comments
 
LVL 9

Expert Comment

by:tinchos
ID: 9913050
If I'm not mistaken you should set the DataGrid's property

RowHeadersVisible to false

DataGrid dg;
// Code

dg.RowHeadersVisible = false;

Hope this helps

Tincho

0
 
LVL 4

Accepted Solution

by:
krznpsk earned 25 total points
ID: 9913102
To eliminate the "Add new record" row that's inserted by default, set the ReadOnly property of the Datagrid to True.

myDataGrid.ReadOnly = True
0
 
LVL 9

Assisted Solution

by:malharone
malharone earned 25 total points
ID: 9914375
or use a list view ... its a great alternative to datagrids when you only want to display the data and disallow editing.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 9

Expert Comment

by:malharone
ID: 9914480
sample:

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        '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
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    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.SuspendLayout()
        '
        'ListView1
        '
        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
        '
        'ContextMenu1
        '
        Me.ContextMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuDetails, Me.mnuList, Me.mnuSmall, Me.mnuLarge})
        '
        'mnuDetails
        '
        Me.mnuDetails.Index = 0
        Me.mnuDetails.Text = "Details"
        '
        'mnuList
        '
        Me.mnuList.Index = 1
        Me.mnuList.Text = "List"
        '
        'mnuSmall
        '
        Me.mnuSmall.Index = 2
        Me.mnuSmall.Text = "Small Icons"
        '
        'mnuLarge
        '
        Me.mnuLarge.Index = 3
        Me.mnuLarge.Text = "Large Icons"
        '
        'Label1
        '
        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"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(496, 310)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.ListView1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    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)
        ds.Tables.Add(dt)
        Dim dr As DataRow
        With dt
            dr = dt.NewRow
            dr("FirstName") = "John"
            dr("LastName") = "Johnson"
            dr("Salary") = 20000
            dt.Rows.Add(dr)

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

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

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

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

            dr = dt.NewRow
            dr("FirstName") = "George"
            dr("LastName") = "Clinton"
            dr("Salary") = 10000
            dt.Rows.Add(dr)
        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)
            Me.ListView1.Items.Add(ili)
        Next
        Me.ListView1.SelectedItems.Clear()
    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
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10287555
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.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer
0
 

Author Comment

by:RameshKanna
ID: 10288414
.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

760 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

20 Experts available now in Live!

Get 1:1 Help Now