Solved

Runing code when form is loading does not work

Posted on 2006-11-15
10
190 Views
Last Modified: 2010-04-23
Hi there

I want to be able to put a link label onto a datagrid.

The following works on a loaded form:

        Dim ColumnToChange As Integer = 2
        Dim CurrentValue As String

        For i As Integer = 0 To DataGridView1.Rows.Count - 1
            CurrentValue = DataGridView1(ColumnToChange, i).Value
            DataGridView1(ColumnToChange, i) = New DataGridViewLinkCell
            DataGridView1(ColumnToChange, i).Value = CurrentValue
        Next

But when it is run on the on_load event or the activated event it runs through the code - but does not display the link label on the grid.

How can I get around this?

many thanks in advance
0
Comment
Question by:DavidGreenfield
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 6

Expert Comment

by:manch
ID: 17946727

use the InitializeComponent event of the form (in the Designer of the Form)
it will work surely and also the way u want

Try It
0
 
LVL 10

Expert Comment

by:Kinger247
ID: 17947773
Hi  DavidGreenfield, put the code in your Form1_Activated event:

    Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
        Dim ColumnToChange As Integer = 2
        Dim CurrentValue As String

        For i As Integer = 0 To DataGridView1.Rows.Count - 1
            CurrentValue = DataGridView1(ColumnToChange, i).Value
            DataGridView1(ColumnToChange, i) = New DataGridViewLinkCell
            DataGridView1(ColumnToChange, i).Value = CurrentValue
        Next
    End Sub
0
 

Author Comment

by:DavidGreenfield
ID: 17949190
I did try the code in the activated event and it still doesn't work.  If i run it from a button click it works though.

For most datagridviews I am showing it doesn't matter - but this one is a static grid that the user can immediately view when loading the screen

thanks for your help
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 6

Expert Comment

by:manch
ID: 17953507

What about the InitializeComponent event (write ur code in the end of this event)

Try . it will work 4 u
0
 

Author Comment

by:DavidGreenfield
ID: 17954790
Hi there manch

I did put it in the initializecomponent event and that didn't work either, I can't seem to tell if it is being run or not though

Should I be putting more than just the link label code in there?
0
 
LVL 10

Expert Comment

by:Kinger247
ID: 17955092
This must mean that the data is still being loaded after these events ?
0
 

Author Comment

by:DavidGreenfield
ID: 17955248
Data takes about 5 seconds to load so possible.

Is there anything I can do to hold off adding a link label until the datagrid has finished loading?
0
 

Author Comment

by:DavidGreenfield
ID: 17963819
I have managed to get around this,

Basically by calling the code as below works:

Public Sub test(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load

I was calling it in (and lots of combinations based on):

Private Sub Form(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

I hope this will help someone else out too!
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 18171242
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.NET 1 27
start a process from a service 3 31
vb.net class 3 21
Retrieve Active Directory Groups a User belongs to in VB.NET 3 18
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question