DavidGreenfield
asked on
Runing code when form is loading does not work
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(ColumnToChan ge, i).Value
DataGridView1(ColumnToChan ge, i) = New DataGridViewLinkCell
DataGridView1(ColumnToChan ge, 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
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(ColumnToChan
DataGridView1(ColumnToChan
DataGridView1(ColumnToChan
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
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(ColumnToChan ge, i).Value
DataGridView1(ColumnToChan ge, i) = New DataGridViewLinkCell
DataGridView1(ColumnToChan ge, i).Value = CurrentValue
Next
End Sub
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(ColumnToChan
DataGridView1(ColumnToChan
DataGridView1(ColumnToChan
Next
End Sub
ASKER
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
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
What about the InitializeComponent event (write ur code in the end of this event)
Try . it will work 4 u
ASKER
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?
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?
This must mean that the data is still being loaded after these events ?
ASKER
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?
Is there anything I can do to hold off adding a link label until the datagrid has finished loading?
ASKER
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!
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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