Results 1 to 4 of 4

Thread: [HELP ME] resize pictures streched in datagribview![for beginner]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2017
    Posts
    96

    Exclamation [HELP ME] resize pictures streched in datagribview![for beginner]

    Hello everybody!
    i have light problem! i have a datagribview with this code:



    For Each DataGridViewImageColumn In Form1.DataGridView2.Columns

    DataGridViewImageColumn.ImageLayout = DataGridViewImageCellLayout.Stretch


    Next


    Form1.DataGridView2.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
    Form1.DataGridView2.RowTemplate.Height = 70
    Dim newItems() As String = Form1.ListBox2.Items.Cast(Of String).Select(Function(s) s.Split(" "c).Last & " " & s.Split(" "c).Last).ToArray
    Dim newItemsA() As String = Form1.ListBox2.Items.Cast(Of String).Select(Function(s) s.Split(" "c).Last & " " & s.Split(" "c).First).ToArray
    Form1.DataGridView2.DataSource = Enumerable.Range(1, newItems.Length).
    Select(Function(n) New With {.Rank = n, .Image = Image.FromFile(Application.StartupPath & "\DANfiles\challengersgif" & newItems(n - 1).Substring(newItems(n - 1).IndexOf(" ") + 1) & ".png"), .Name = newItemsA(n - 1)}).
    ToArray()



    but the second column with pictures are not resized or no streched. i would like a piece of coding in order to the pictures be resized or same size streched.


    thank you in advance for your answers and help!
    sorry for my english, i am from france and started coding.

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

    Re: [HELP ME] resize pictures streched in datagribview![for beginner]

    How many columns are there in that grid and how many of them are image columns? Where exactly is the code you just posted located? How exactly is Form1 displayed? Why are you configuring the image column in code rather than in the designer?

    On a more rhetorical note, why aren't you using descriptive names for things? You should have anything named Form1, ListBox2 or DataGridView2 in your application. Those names are meaningless when it comes to understanding what the things they refer to are actually for.
    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

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2017
    Posts
    96

    Re: [HELP ME] resize pictures streched in datagribview![for beginner]

    Quote Originally Posted by jmcilhinney View Post
    How many columns are there in that grid and how many of them are image columns? Where exactly is the code you just posted located? How exactly is Form1 displayed? Why are you configuring the image column in code rather than in the designer?

    On a more rhetorical note, why aren't you using descriptive names for things? You should have anything named Form1, ListBox2 or DataGridView2 in your application. Those names are meaningless when it comes to understanding what the things they refer to are actually for.
    there is 3 columns and the number of pictures is variable (more 250 pictures)
    form1.windowstate = normal
    my code is on form2 for memory(load a lot of pictures)

    "Why are you configuring the image column in code rather than in the designer?"
    _i am just discovering the datagrib and this code solve my problem exept the pictires are not streched.

    "Those names are meaningless when it comes to understanding what the things they refer to are actually for."
    _you are right it is from my application but my real problem is to streched the pictures in the second column from my datagribview.

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

    Re: [HELP ME] resize pictures streched in datagribview![for beginner]

    Quote Originally Posted by danzey View Post
    there is 3 columns and the number of pictures is variable (more 250 pictures)
    form1.windowstate = normal
    my code is on form2 for memory(load a lot of pictures)
    It doesn't matter how many images there are. I asked how many image COLUMNS there are. It seems as though there is only one, in which case this code doesn't make sense for two reasons:
    vb.net Code:
    1. For Each DataGridViewImageColumn In Form1.DataGridView2.Columns
    2.     DataGridViewImageColumn.ImageLayout = DataGridViewImageCellLayout.Stretch
    3. Next
    The whole point of a loop is to do the same thing multiple times but if you only have one image column then you don't need to do anything multiple times, so you don't need a loop to begin with. Also, if not every column is an image column then that code will throw an as soon as it finds a column that does not have an ImageLayout property. You should just be setting that property on the one column of the right type directly.
    Quote Originally Posted by danzey View Post
    "Why are you configuring the image column in code rather than in the designer?"
    _i am just discovering the datagrib and this code solve my problem exept the pictires are not streched.
    If you are adding the columns in the designer, which you probably ought to be, then you can just set that property in the designer.
    Quote Originally Posted by danzey View Post
    "Those names are meaningless when it comes to understanding what the things they refer to are actually for."
    _you are right it is from my application but my real problem is to streched the pictures in the second column from my datagribview.
    I understand that that's the problem you're posting about - no need to repeat it multiple times - but that doesn't mean that you can't learn nayhting else and make any other beneficial changes.
    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

Tags for this Thread

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