Results 1 to 5 of 5

Thread: [RESOLVED] [2005] Only enable 1 column in dataGridview?

  1. #1

    Thread Starter
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Resolved [RESOLVED] [2005] Only enable 1 column in dataGridview?

    Is there a simple way to only enable the 1st column in a datagrid. I want the user to simply select a range or single items from column 1 which are then added to a listbox.

    The problem is if they start selecting from the other columns. I put different events in like on Cell Click etc... to jump to the 1st column but there's too much that can go wrong. Would be simpler to just only enable 1 column.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  2. #2
    Fanatic Member MetalKid's Avatar
    Join Date
    Aug 2005
    Location
    Green Bay, Wisconsin
    Posts
    534

    Re: [2005] Only enable 1 column in dataGridview?

    Code:
            For i As Int32 = 1 To grid.Columns.Count - 1
                grid.Columns(i).ReadOnly = True
            Next
    or

    Code:
            For i As Int32 = 1 To grid.Columns.Count - 1
                grid.Columns(i).Visible= True
            Next
    If your problem is solved, please use the Mark Thread As Resolved under Thread Tools!

    Show Appreciation. Rate Posts!

  3. #3

    Thread Starter
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Only enable 1 column in dataGridview?

    I need all columns to be displayed, but only the cells in column 1 to actually be selectable.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Only enable 1 column in dataGridview?

    Just set SelectionMode to FullRowSelect, then get the value from the first column in all the selected rows.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Only enable 1 column in dataGridview?

    Cheers JMC,

    I did it using this for anyone else learning it who might find it useful in the future:

    vb Code:
    1. For Each itm As DataGridViewRow In Me.DataGridView1.SelectedRows
    2.          Me.ListBox1.Items.Add(Me.DataGridView1.Item(0, itm.Index).Value.ToString)
    3. Next
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width