Solved

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

Posted on 2003-12-10
7
390 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

740 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