Solved

Runing code when form is loading does not work

Posted on 2006-11-15
10
202 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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.

739 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