Solved

Runing code when form is loading does not work

Posted on 2006-11-15
10
162 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
Comment Utility

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
Comment Utility
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
Comment Utility
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
 
LVL 6

Expert Comment

by:manch
Comment Utility

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

Try . it will work 4 u
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:DavidGreenfield
Comment Utility
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
Comment Utility
This must mean that the data is still being loaded after these events ?
0
 

Author Comment

by:DavidGreenfield
Comment Utility
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
Comment Utility
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
Comment Utility
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now