Solved

Runing code when form is loading does not work

Posted on 2006-11-15
10
198 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 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