Hjälp ! Datatabellen fylles hela tiden i oändlighet, Den måste tas bort och skapas Hur ? Lär dig hur kodtaggen fungerar så kan folk kläsa din kod.... Skala även bort bortkommenterade kodrader mm så ökar chansed att du skall få svar Tack Marcus Gus Hej Marcus tack för inslaget, det ör lite olika beroende på om det är VS2003 eller VS2005. Hinner inte ta det nu, men kan dra det imorgon om ingen har svarat innan dess och om du säger vilken version du använder. vs2003Datagrid funkar fortfarande inte med timer dvs att uppdatera datagrid 1 gång var
Har lagt hela koden för formuläret, blir snart tokigare än vad jag är med v h
per
Imports System
Imports System.IO
Imports System.Threading
Imports System.Text
Imports System.Data
'Imports System.Data.SqlTypes
Imports System.Data.SqlClient
'Imports System.Data.SqlClient.SqlCommand
Imports System.Data.SqlClient.SqlConnection
'Imports System.Data.SqlClient.SqlParameter
Imports System.Data.SqlClient.SqlTransaction
Public Class TR1
Inherits System.Windows.Forms.Form
Private mojb As S1_t_1
Private mojb1 As S2_t_1
Private mojb2 As S3_t_1
Private mojb3 As S4_t_1
Private mojb4 As S5_t_1
Private mojb5 As s6_t_1
Private soi As DTG1_1M
Public lllo As String
Public sokkvv_1 As String
Public sokkvv_5 As String
Public sokkvv_20 As String
Public sokkvv_60 As String
Private MSDATASET As New DataSet
Private MPDAD As SqlDataAdapter
Private WithEvents MTBL As DataTable
Private counter As Integer
Private Structure namna
Public namm As String
End Structure
Private nper As namna
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Timer1 As System.Windows.Forms.Timer
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
Friend WithEvents r1 As System.Windows.Forms.DataGridTableStyle
Friend WithEvents co1 As System.Windows.Forms.DataGridTextBoxColumn
Friend WithEvents co2 As System.Windows.Forms.DataGridTextBoxColumn
Friend WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.r1 = New System.Windows.Forms.DataGridTableStyle
Me.co1 = New System.Windows.Forms.DataGridTextBoxColumn
Me.co2 = New System.Windows.Forms.DataGridTextBoxColumn
Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(536, 360)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(152, 20)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = ""
'
'Timer1
'
'
'DataGrid1
'
Me.DataGrid1.DataMember = ""
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(56, 8)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size(456, 888)
Me.DataGrid1.TabIndex = 2
Me.DataGrid1.TableStyles.AddRange(New System.Windows.Forms.DataGridTableStyle() {Me.r1})
'
'r1
'
Me.r1.DataGrid = Me.DataGrid1
Me.r1.GridColumnStyles.AddRange(New System.Windows.Forms.DataGridColumnStyle() {Me.co1, Me.co2})
Me.r1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.r1.MappingName = "vlo"
'
'co1
'
Me.co1.Format = ""
Me.co1.FormatInfo = Nothing
Me.co1.HeaderText = "ett"
Me.co1.MappingName = ""
Me.co1.Width = 20
'
'co2
'
Me.co2.Format = ""
Me.co2.FormatInfo = Nothing
Me.co2.HeaderText = "r2"
Me.co2.MappingName = "ar2"
Me.co2.Width = 75
'
'TR1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(712, 966)
Me.Controls.Add(Me.DataGrid1)
Me.Controls.Add(Me.TextBox1)
Me.Name = "TR1"
Me.Text = "TR1"
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Public Function namn(ByRef nmn As String) As String
Return nmn
End Function
Private Sub tr1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ska As String
Dim rmt As C_TA1 = New C_TA1
INfTXT.namntxt(lllo)
'TextBox1.Text = rmt.ob
skrint()
storaseller()
InitializeTimer()
' skrint1()
'Timer1.Interval = 1
'storaseller()
'AddCustomDataTableStyle()
End Sub
Private Sub InitializeTimer()
' Run this procedure in an appropriate event.
counter = 0
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'If counter >= 10 Then
' Exit loop code.
' Timer1.Enabled = False
' counter = 0
' Else
'If vaxl.skvtaemot = 6 Then
counter = counter + 1
TextBox1.Text = "Procedures Run: " & Now
storaseller()
' End If
' vaxl.skvtaemot_nolla()
' Run your procedure here.
' Increment counter.
'counter = counter + 1
' TextBox1.Text = "Procedures Run: " & counter.ToString
End Sub
Private Sub skrint()
Dim rmt As C_TA1 = New C_TA1
mojb = New S1_t_1
mojb.namn = lllo
mojb.sokv = sokkvv_1
mojb1 = New S2_t_1
mojb1.namn = lllo
mojb1.sokv = sokkvv_1
mojb2 = New S3_t_1
mojb2.namn = lllo
mojb2.sokv = sokkvv_1
mojb3 = New S4_t_1
mojb3.namn = lllo
mojb3.sokv = sokkvv_1
mojb4 = New S5_t_1
mojb4.namn = lllo
mojb4.sokv = sokkvv_1
mojb5 = New s6_t_1
mojb5.namn = lllo
mojb5.sokv = sokkvv_1
' soi = New DTG1_1M
' soi.namn = lllo
' soi.sokv = sokkvv_1
'TextBox1.Text = mojb.ar1
'Timer1.Enabled = True
End Sub
Private Sub storaseller()
Dim cn As New SqlConnection
cn.ConnectionString = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Trading;Data Source=SMO;Packet Size=4096;Workstation ID=SMO"
Dim STR As String = "SELECT SIGNAL,S1,S2,S3,S4,S5,S6,OM1,OM2,OM3,OM4,OM5,OM6 FROM TR@EC"
MPDAD = New SqlDataAdapter(STR, cn)
Dim CMDBYLD As New SqlCommandBuilder(MPDAD)
MPDAD.Fill(MSDATASET, "TR@EC")
MTBL = MSDATASET.Tables(0)
DataGrid1.PreferredColumnWidth = 50
DataGrid1.DataSource = MTBL
DataGrid1.Refresh()
DataGrid1.Update()
DataGrid1.Show()
'cn.Close()
End Sub
Private Sub form_close()
mojb1.avsluta()
mojb1 = Nothing
mojb5.avsluta()
mojb5 = Nothing
mojb4.avsluta()
mojb4 = Nothing
mojb3.avsluta()
mojb3 = Nothing
mojb2.avsluta()
mojb2 = Nothing
mojb.avsluta()
mojb = Nothing
End Sub
End ClassSv: Datagrid funkar fortfarande inte med timer dvs att uppdatera datagrid 1 gång
mvh PerSv:Datagrid funkar fortfarande inte med timer dvs att uppdatera datagrid 1 gång
testa
<code>
Private Sub storaseller()
Dim cn As New SqlConnection
dim MSDATASET As New DataSet
dim MPDAD As SqlDataAdapter
cn.ConnectionString = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Trading;Data Source=SMO;Packet Size=4096;Workstation ID=SMO"
Dim STR As String = "SELECT SIGNAL,S1,S2,S3,S4,S5,S6,OM1,OM2,OM3,OM4,OM5,OM6 FROM TR@EC"
MPDAD = New SqlDataAdapter(STR, cn)
Dim CMDBYLD As New SqlCommandBuilder(MPDAD)
MPDAD.Fill(MSDATASET, "TR@EC")
DataGrid1.PreferredColumnWidth = 50
DataGrid1.DataSource = MSDATASET.Tables(0)
me.invalidate(true)
cn.Close()
End Sub
</code>Sv: Datagrid funkar fortfarande inte med timer dvs att uppdatera datagrid 1 gång
dena kod gav susen
me.invalidate(true)
tusen och åter tusen tack
ska försöka bättra mig
Mvh Per HSv: Datagrid funkar fortfarande inte med timer dvs att uppdatera datagrid 1 gång
en liten undran
jag är ej van med datagridar osv
med det jag vill få in är att färgsätta
siffrorna som kommer in i olika färger beroende på värdet
hur beter jag mig då
mvh
per höglundSv:Datagrid funkar fortfarande inte med timer dvs att uppdatera datagrid 1 gång
Sv: Datagrid funkar fortfarande inte med timer dvs att uppdatera datagrid 1 gång
Väntar med spänning
mvh Per