Results 1 to 4 of 4

Thread: Datagridview to control picturebox width Help

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    3

    Datagridview to control picturebox width Help

    Hi everyone, new to the forums here and I needed some hekp with a program I'm working on. Basically, I have a datagridview and I want to use values inputed into it to control the position and width of pictureboxes. When I use my code I get an index out of range error for any row other than the first one. When I have only the code for the first row it works, when I add more it doesnt.

    Heres the code so far:

    under form load:

    DataGridView.Rows.Add(28)

    under datagridview value changed event:

    picBar1.Width = DataGridView.Item(3, 0).Value * 27
    picBar1.Location = New Point(picCalendar31.Location.X + DataGridView.Item(2, 0).Value * 27 , picBar1.Location.Y)

    picBar2.Width = DataGridView.Item(3, 1).Value * 27
    picBar2.Location = New Point(picCalendar31.Location.X + DataGridView.Item(2, 1).Value * 27 , picBar2.Location.Y)

    Any help is appreciated, thanks

  2. #2

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    3

    Re: Datagridview to control picturebox width Help

    BTW it is an unbounded datagridview

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

    Re: Datagridview to control picturebox width Help

    Can we assume that you mean the CellValueChanged event? You should always use the actual names for things rather than approximations that require assumptions to be made. You'll avoid confusion that way.

    If you're handling the CellValueChanged event then why aren't you using the ColumnIndex and/or RowIndex provided by the event? Also, you are using data from two different rows. How does that work? We need a full and clear description.
    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

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    3

    Re: Datagridview to control picturebox width Help

    Yes it is th CellValueChanged Event. And I am using different rows becuase I have multiple pictureboxes. The first row in the datagridview corresponds to the first picturebox, the second row to the second picturebox and so on.

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