DataGridView (Removing bar on left help)

DeltaWolf7

Well-known member
Joined
Jan 21, 2006
Messages
47
Programming Experience
Beginner
Hi,

How do you remove the column that is automatically created on the left side of a datagridview box?
I know I would use a listbox to create a list of items, but i want to add an icon to the entries.

Unless anyone knows a way to put icons in listboxes.

I am using VB.Net 2005

Thank you
 
Small example for ListBox (probably not needed anymore, but I already made it, before checking the DataGridView Class, so here goes anyway:)
You could retrieve the icons from an ImageList, or from resource, here I just draw a rectangle in a color depending on the value of the item (string) that is drawn:

VB.NET:
[COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Sub[/COLOR] ListBoxColorsDrawItem([COLOR=#0000ff]ByVal[/COLOR] sender [COLOR=#0000ff]As[/COLOR] System.Object, _
[COLOR=#0000ff]ByVal[/COLOR] e [COLOR=#0000ff]As[/COLOR] System.Windows.Forms.DrawItemEventArgs) _
[COLOR=#0000ff]Handles[/COLOR] ListBoxColors.DrawItem
    [COLOR=#0000ff]Dim[/COLOR] lb [COLOR=#0000ff]As[/COLOR] ListBox = [COLOR=#0000ff]DirectCast[/COLOR](sender, ListBox)
    [COLOR=#0000ff]Dim[/COLOR] rect [COLOR=#0000ff]As[/COLOR] Rectangle = e.Bounds
    [COLOR=#0000ff]Dim[/COLOR] item [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]String[/COLOR] = lb.Items(e.Index).ToString
    [COLOR=#0000ff]Dim[/COLOR] b [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]New[/COLOR] SolidBrush(Color.FromName(item))
    e.DrawBackground()
    e.Graphics.DrawRectangle(Pens.Silver, rect)
    rect.Width = rect.Height
    rect.Inflate(-2, -2)
    e.Graphics.FillRectangle(b, rect)
    b.Dispose()
    b = [COLOR=#0000ff]New[/COLOR] SolidBrush(e.ForeColor)
    rect = e.Bounds
    e.Graphics.DrawString(item, lb.Font, b, rect.Left + lb.ItemHeight + 4, rect.Top + 2)
    [COLOR=#0000ff]If[/COLOR] e.State = DrawItemState.Selected [COLOR=#0000ff]Then[/COLOR] e.DrawFocusRectangle()
[COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Sub[/COLOR]
 
 
[COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Sub[/COLOR] FormMain_Load([COLOR=#0000ff]ByVal[/COLOR] sender [COLOR=#0000ff]As[/COLOR] System.Object, [COLOR=#0000ff]ByVal[/COLOR] e [COLOR=#0000ff]As[/COLOR] System.EventArgs) _
[COLOR=#0000ff]Handles[/COLOR] [COLOR=#0000ff]MyBase[/COLOR].Load
    ListBoxColors.ItemHeight = 17
    [COLOR=#0000ff]For[/COLOR] [COLOR=#0000ff]Each[/COLOR] c [COLOR=#0000ff]As[/COLOR] KnownColor [COLOR=#0000ff]In[/COLOR] [Enum].GetValues([COLOR=#0000ff]GetType[/COLOR](KnownColor))
        [COLOR=#0000ff]If[/COLOR] c > KnownColor.YellowGreen [COLOR=#0000ff]Or[/COLOR] c < KnownColor.AliceBlue [COLOR=#0000ff]Then[/COLOR] [COLOR=#0000ff]Continue[/COLOR] [COLOR=#0000ff]For[/COLOR]
        ListBoxColors.Items.Add(c.ToString)
    [COLOR=#0000ff]Next[/COLOR]
[COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Sub[/COLOR]
 
Wow, thank you very much.

You are a god.. I wish I was that good. lol, I have only just started learning the language myself. I bet you can tell that much about me. ;)

Thank you very much.
 
Back
Top