Bakgrund två liknande färgsättningar varav ena ligger i en inne i en ticker och den funkar ejKnepigt felmeddelande vid färgsättning av datagrid ! troligtvis enkelt
medans den som ligger vid form_loud fungerar
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.ArgumentException: The data grid table styles collection already contains a table style with the same mapping name.
Parameter name: table
at System.Windows.Forms.GridTableStylesCollection.CheckForMappingNameDuplicates(DataGridTableStyle table)
at System.Windows.Forms.GridTableStylesCollection.Add(DataGridTableStyle table)
at TerminTR.TK.snrurrKA() in C:\Documents and Settings\HP_Ägaren\Mina dokument\Visual Studio Projects\TerminTR\TK.vb:line 250
at TerminTR.TK.Timer1_Tick(Object sender, EventArgs e) in C:\Documents and Settings\HP_Ägaren\Mina dokument\Visual Studio Projects\TerminTR\TK.vb:line 2445
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr idEvent, IntPtr dwTime)
Denna sub ligger inne i en ticker
Det som inte funkar !
Private Sub snrurrKA()
Dim MSDATASET As New DataSet
Dim MPDAD As SqlDataAdapter
Dim MTBL As New DataTable
Dim obdt As New DataGridTableStyle
Dim obtc As New DataGridTextBoxColumn
Dim colbtc As New kopcolumn_s
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 obadapter As New SqlDataAdapter
Dim objdatas As DataSet = New DataSet
cn.Open()
obadapter.SelectCommand = New SqlCommand
obadapter.SelectCommand.Connection = cn
obadapter.SelectCommand.CommandText = "SNURRAKOP"
Dim OPAR1 As SqlParameter = obadapter.SelectCommand.Parameters.Add("@L", SqlDbType.Decimal)
OPAR1.Value = THLC_tr1.LOUT
Dim OPAR2 As SqlParameter = obadapter.SelectCommand.Parameters.Add("@PT", SqlDbType.NVarChar)
OPAR2.Value = "BA"
obadapter.SelectCommand.CommandType = CommandType.StoredProcedure
obadapter.SelectCommand.ExecuteNonQuery()
obadapter.Fill(objdatas, "Snurran@EC")
cn.Close()
obadapter = Nothing
cn = Nothing
obdt.MappingName = "Snurran@EC"
obtc.MappingName = "Onamn"
obtc.HeaderText = "Onamn"
obtc.Width = 40
obdt.GridColumnStyles.Add(obtc)
obtc.MappingName = "OM"
obtc.HeaderText = "OM"
obtc.Width = 40
obdt.GridColumnStyles.Add(obtc)
obtc.MappingName = "Tidsp"
obtc.HeaderText = "Tidp"
obtc.Width = 10
obdt.GridColumnStyles.Add(obtc)
obtc.MappingName = "np"
obtc.HeaderText = "Np"
obtc.Width = 10
obdt.GridColumnStyles.Add(obtc)
colbtc.MappingName = "Göra"
colbtc.HeaderText = "Göra"
colbtc.Width = 30
obdt.GridColumnStyles.Add(colbtc)
DataGrid13.TableStyles.Add(obdt)
DataGrid13.DataSource = objdatas
DataGrid13.DataMember = "Snurran@EC"
DataGrid13.CaptionText = "Snurran KOP AVG"
DataGrid13.CaptionBackColor = Color.Blue
DataGrid13.CaptionForeColor = Color.Black
DataGrid13.Show()
Me.Invalidate(True)
End Sub
Public Class kopcolumn_s
Inherits DataGridTextBoxColumn
Protected Overloads Overrides Sub paint(ByVal graph As Graphics, ByVal restbounds As Rectangle, ByVal curmngrSrc As CurrencyManager, ByVal Rownumber As Integer, ByVal forecolorBrush As Brush, ByVal Backcolorbrush As Brush, ByVal alignementright As Boolean)
Dim objval As Object
objval = Me.GetColumnValueAtRow(curmngrSrc, Rownumber)
If Not (IsNothing(objval) Or IsDBNull(objval)) Then
Dim cellvalue As String
cellvalue = CType(objval, String)
If (cellvalue = "kop") Then
Backcolorbrush = Brushes.Black
forecolorBrush = Brushes.Green
Else
Backcolorbrush = Brushes.Black
forecolorBrush = Brushes.White
End If
End If
MyBase.paint(graph, restbounds, curmngrSrc, Rownumber, forecolorBrush, Backcolorbrush, alignementright)
End Sub
End Class
Denna funkar
skillnaden är att jag sätter denna med form loud och den uppdateras ej senare under dagen
Private Sub EXMAN_G()
Dim MSDATASET As New DataSet
Dim MPDAD As SqlDataAdapter
Dim MTBL As New DataTable
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 obadapter As New SqlDataAdapter
Dim objdatas As DataSet = New DataSet
cn.Open()
obadapter.SelectCommand = New SqlCommand
obadapter.SelectCommand.Connection = cn
obadapter.SelectCommand.CommandText = "EXMANFT1v"
obadapter.SelectCommand.CommandType = CommandType.StoredProcedure
obadapter.SelectCommand.ExecuteNonQuery()
obadapter.Fill(objdatas, "aexgFT1@EC")
cn.Close()
obadapter = Nothing
cn = Nothing
Dim obdt As New DataGridTableStyle
Dim obtc As New DataGridTextBoxColumn
Dim colbtc As New SALJCOLLERDCOLUMN_I
obdt.MappingName = "aexgFT1@EC"
obtc.MappingName = "tid"
obtc.HeaderText = "tid"
obtc.Width = 40
obdt.GridColumnStyles.Add(obtc)
colbtc.MappingName = "antal"
colbtc.HeaderText = "antal"
colbtc.Width = 20
obdt.GridColumnStyles.Add(colbtc)
DataGrid10.TableStyles.Add(obdt)
DataGrid10.DataSource = objdatas
DataGrid10.DataMember = "aexgFT1@EC"
DataGrid10.CaptionText = "EXMAN "
DataGrid10.CaptionBackColor = Color.Blue
DataGrid10.CaptionForeColor = Color.Black
DataGrid10.Show()
Me.Invalidate(True)
End Sub
klassen
Public Class SALJCOLLERDCOLUMN_I
Inherits DataGridTextBoxColumn
Protected Overloads Overrides Sub paint(ByVal graph As Graphics, ByVal restbounds As Rectangle, ByVal curmngrSrc As CurrencyManager, ByVal Rownumber As Integer, ByVal forecolorBrush As Brush, ByVal Backcolorbrush As Brush, ByVal alignementright As Boolean)
Dim objval As Object
objval = Me.GetColumnValueAtRow(curmngrSrc, Rownumber)
If Not (IsNothing(objval) Or IsDBNull(objval)) Then
Dim cellvalue As Integer
cellvalue = CType(objval, Integer)
If (cellvalue > 0) Then
Backcolorbrush = Brushes.Black
forecolorBrush = Brushes.Red
Else
' If (cellvalue = 2) Then
Backcolorbrush = Brushes.Black
forecolorBrush = Brushes.White
End If
' If (cellvalue = 6) Then
' Backcolorbrush = Brushes.Black
' forecolorBrush = Brushes.PaleVioletRed
' End If
' If (cellvalue < 1) Then
' Backcolorbrush = Brushes.White
' forecolorBrush = Brushes.White
' End If
End If
MyBase.paint(graph, restbounds, curmngrSrc, Rownumber, forecolorBrush, Backcolorbrush, alignementright)
End Sub
End Class
mvh Per H