VS 2013 Windows Form datagridview problems with .NET 4.6.1-VBForums
Results 1 to 17 of 17

Thread: VS 2013 Windows Form datagridview problems with .NET 4.6.1

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    15

    VS 2013 Windows Form datagridview problems with .NET 4.6.1

    I've a Windows Form VS 2013 application that is configured to require at a minimum .NET Framework 4.0. This application is distributed to several different pharma customers.

    I have .NET 4.5.2 installed on my development machine. All users have a mix of .NET 4.0 to .NET 4.5.2. I've never had a problem with the application.

    A customer just started to have problems. I noticed that their IT dept pushed down .NET 4.6.1 to all client machines. I've identified that, in a .NET 4.6.1 environment, when the datagridview.columns(x).minimumwidth property is set in code, the following error is trapped: "Object reference not set to an instance of an object." Which is goofy because several datagridview properties are set in previous lines in the code.

    Even more goofy is that this happens with only two out of ~50 datagridview objects - all the other "datagridview.columns(x).minimumwidth = xx" lines of code do not result in error.

    Notes;
    1. I've tried deleting the two datagridviews and recreating them, but no luck.

    I've found sporadic compatibility complaints about .NET 4.6.1, but haven't found anything specific about 4.6.1 and datagridviews. I've found this general post by Microsoft describing .NET 4.6.1: https://msdn.microsoft.com/en-us/lib...0%29.aspx#v461 This post has something about 4.5.2 and 4.6.1 and a new 'EnableWindowsFormsHighDpiAutoResizing' element, but it's an opt-in feature and shouldn't affect datagridviews as they reside in my application: "...This is an opt-in feature. To enable it, set the EnableWindowsFormsHighDpiAutoResizing element to true in the application configuration (app.config) file...."

    I actually tried enabling EnableWindowsFormsHighDpiAutoResizing, but it had no effect - the error still occurred in a 4.6.1 environment.

    If anyone has any insight to this issue, that would be great. Thanx!

  2. #2
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,592

    Re: VS 2013 Windows Form datagridview problems with .NET 4.6.1

    Did you stop the execution of the program at that point and see which object is the offending one?
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    15

    Re: VS 2013 Windows Form datagridview problems with .NET 4.6.1

    Hi kaliman,

    Yes, I did. From the original post: "...Even more goofy is that this happens with only two out of ~50 datagridview objects ..." So I know exactly which two datagridviews are causing the problems and I've added appropriate try-catch statements when the code attempts to set the "datagridview.columns(x).minimumwidth = xx" property. However, I have no idea why these minimumwidth statements are causing the error "Object reference not set to an instance of an object."

  4. #4
    Fanatic Member
    Join Date
    Feb 2013
    Posts
    875

    Re: VS 2013 Windows Form datagridview problems with .NET 4.6.1

    when you step through the code check each object of your code and drill down further into the problem

    example, at the problem parts

    i recommend using watches since you can see everything right away........

    add watch for the following
    1) datagridview.columns(x).minimumwidth ......does this give a value or object ref error
    2) datagridview.columns(x) ......does this give an outofbounds or index type of error, its a collection/array
    3) datagridview.columns ......same as above....if OK, check its items, item count compare your x variable etc
    4) datagridview ......if this gives an abject ref error, or is nothing then houston we have a problem

    this is going to at least quickly tell you exactly where the problem is.......... it may not be with the .MinimumWidth part as you believe.
    Yes!!!
    Working from home is so much better than working in an office...
    Nothing can beat the combined stress of getting your work done on time whilst
    1. one toddler keeps pressing your AVR's power button
    2. one baby keeps crying for milk
    3. one child keeps running in and out of the house screaming and shouting
    4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
    5. working at 1 O'clock in the morning because nobody is awake at that time
    6. being grossly underpaid for all your hard work


  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    15

    Re: VS 2013 Windows Form datagridview problems with .NET 4.6.1

    Hi GBeats,

    I've already done something similar in the code. I embedded each of the following lines in try-catch statements. The only line that throws an error is the line described in underlined bold italics:

    dim dgv as datagridview = me.dgvSamples

    int1 = dgv.Columns.Count ' This returns int1 = 2. So there are two columns in the datagridview
    dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
    dgv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders
    dgv.DefaultCellStyle.WrapMode = DataGridViewTriState.True
    For Count2 = 0 To int1 - 1
    dgv.Columns.Item(Count2).SortMode = DataGridViewColumnSortMode.NotSortable 'This sets a property for both columns without error, so dgv.Columns.Item(1) is OK
    Next
    dgv.Columns.Item(0).ReadOnly = True 'No problem here
    dgv.AllowUserToResizeColumns = True
    dgv.AllowUserToResizeRows = True
    dgv.RowHeadersWidth = 25
    If int1 < 1 Then
    Else
    dgv.Columns.Item(1).MinimumWidth = 150 'This code throws the error "Object reference not set to an instance of an object."
    End If
    dgv.Columns(0).Width = 150 'No problem here
    dgv.AutoResizeColumns()
    dgv.AutoResizeRows()

  6. #6
    Fanatic Member
    Join Date
    Feb 2013
    Posts
    875

    Re: VS 2013 Windows Form datagridview problems with .NET 4.6.1

    dgv.Columns.Item(1).MinimumWidth = 150

    what is this value when the breakpoint is on this line

    i read that column.width overrides column.minimumwidth could there be a problem with this.... maybe try setting the width to 151 before settings minimum width to 150?? maybe a bug..
    Last edited by GBeats; May 12th, 2016 at 09:26 AM.
    Yes!!!
    Working from home is so much better than working in an office...
    Nothing can beat the combined stress of getting your work done on time whilst
    1. one toddler keeps pressing your AVR's power button
    2. one baby keeps crying for milk
    3. one child keeps running in and out of the house screaming and shouting
    4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
    5. working at 1 O'clock in the morning because nobody is awake at that time
    6. being grossly underpaid for all your hard work


  7. #7

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    15

    Re: VS 2013 Windows Form datagridview problems with .NET 4.6.1

    Hi GBeats,

    Remember, none of these errors happen on my development machine (.NET 4.5.2). I trapped these errors on the customer's machine (.NET 4.6.1) with the code that has the multiple try-catch statements.

    On my machine, the value returned is 5, which I believe is the default setting for a datagridview column(x).minimumwidth. On the customer's machine, I would not be able to trap/return this value because the
    dgv.columns.item(1).MinimumWidth property itself returns the error "Object reference not set to an instance of an object." To clarify, '...Object...' in this case isn't the datagridview object, '...Object..." is the dgv.columns.item(1).MinimumWidth property.

    I'm in the process of setting up a VMware development machine that I'll configure with .NET 4.6.1 and I'll be able to investigate better.

  8. #8
    Fanatic Member
    Join Date
    Feb 2013
    Posts
    875

    Re: VS 2013 Windows Form datagridview problems with .NET 4.6.1

    im just throwing ideas up here , i was suggesting setting a width may somehow cause a problem later when setting a minimum width....... its obviously a bug somewhere (or something thats been overlooked on our/your part) so you need to start thinking out of the box, you wont find a bug by being logical (in a certain sense )

    if it was me i would try changing my code slightly.... instead of using object.columns.item(#), use object.columns(#)... visa versa, you never know
    Yes!!!
    Working from home is so much better than working in an office...
    Nothing can beat the combined stress of getting your work done on time whilst
    1. one toddler keeps pressing your AVR's power button
    2. one baby keeps crying for milk
    3. one child keeps running in and out of the house screaming and shouting
    4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
    5. working at 1 O'clock in the morning because nobody is awake at that time
    6. being grossly underpaid for all your hard work


  9. #9

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    15

    Re: VS 2013 Windows Form datagridview problems with .NET 4.6.1

    Hi GBeats,

    I haven't physically set the columnwidth anywhere, so no conflict there. I can't test with the customer anymore because he was getting annoyed with all the testing I had to do on his machine. I'm creating a VMware dev .NET 4.6.1 environment, so should be able to find out more.

    I don't think it's a bug because the error never happened in the past with this application ranging from .NET 3.5 to .NET 4.5.2. The error only happens with .NET 4.6.1. I suspect Microsoft is the culprit - I've found a few other posts on other forums of people reporting backwards compatibility issues with .NET 4.6.1.

    I appreciate your input.

  10. #10
    Fanatic Member
    Join Date
    Feb 2013
    Posts
    875

    Re: VS 2013 Windows Form datagridview problems with .NET 4.6.1

    new technology bring new problems........... i dont think that way but its always in the back of my mind, your only solution is wait until a fix is presented or find some weird workaround that kind of fixes the problem....... i never had this problem with .NET personally but i had it countless times developing on office and sometimes it just doesnt make sense and its a pain.....

    i personally suggest you get rid of the offending line of code and find some (probably rediculus) workaround just so your already annoyed client doesnt loose all faith , i have definitely been there before haha.

    i might goto the columnresize events and hardcode my own minimum size in there, along with any initial grid formatting code you have......
    Yes!!!
    Working from home is so much better than working in an office...
    Nothing can beat the combined stress of getting your work done on time whilst
    1. one toddler keeps pressing your AVR's power button
    2. one baby keeps crying for milk
    3. one child keeps running in and out of the house screaming and shouting
    4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
    5. working at 1 O'clock in the morning because nobody is awake at that time
    6. being grossly underpaid for all your hard work


  11. #11
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,592

    Re: VS 2013 Windows Form datagridview problems with .NET 4.6.1

    Hello again. in your code
    Code:
    If int1 < 1 Then
    Else
    dgv.Columns.Item(1).MinimumWidth = 150 'This code throws the error "Object reference not set to an instance of an object." 
    End If
    I will not get into the empty IF - THEN but the issue is that there is no warranty that if Int1 is not < 1, there is a Columns.Item(1). Because Int1 could be 1, this means the columns array has only one element being Columns.Item(0). Check the value of Int1 when you get the exception at this point, I bet is "1"
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  12. #12

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    15

    Re: VS 2013 Windows Form datagridview problems with .NET 4.6.1

    Hi Kaliman,

    From the original post:

    .
    .
    int1 = dgv.Columns.Count ' This returns int1 = 2. So there are two columns in the datagridview
    .
    .

  13. #13

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    15

    Re: VS 2013 Windows Form datagridview problems with .NET 4.6.1

    And actually the If statement is incorrect. It should read:

    If int1 < 2 Then....

    The 'empty' part is by design. If int1 < 2, then I don't want to do anything.

  14. #14

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    15

    Re: VS 2013 Windows Form datagridview problems with .NET 4.6.1

    And I have checked the value of int1 just before this If-Then statement; int1 = 2

  15. #15

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    15

    Re: VS 2013 Windows Form datagridview problems with .NET 4.6.1

    Also, when the error is trapped and the code continues to the GUI, the offending datagridview has two columns as expected.

  16. #16
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,592

    Re: VS 2013 Windows Form datagridview problems with .NET 4.6.1

    Quote Originally Posted by gubbs View Post
    And actually the If statement is incorrect. It should read:

    If int1 < 2 Then....

    The 'empty' part is by design. If int1 < 2, then I don't want to do anything.
    The it should be

    IF int1 >= 2 THEN

    and not leave part of the statement empty. But this is just aesthetics, it does not fix your problem
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  17. #17
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,592

    Re: VS 2013 Windows Form datagridview problems with .NET 4.6.1

    I would suggest to put Column(1) itself in the watch window and explore all its properties to see if you find something odd.
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.