|
Next, define a collection of DataColumn s:
Imports System.ComponentModel
Imports System.Collections
Imports System.Windows.Forms
Public Class DataColumnCollection : Inherits CollectionBase
Private _Parent As Control
#Region "Constructors"
Public Sub New()
'Do Nothing
End Sub
Public Sub New(ByVal Value() As DataColumn)
AddRange(Value)
End Sub
Public Sub New(ByVal Value As DataColumnCollection)
AddRange(Value)
End Sub
#End Region
#Region "Add"
Public Function Add(ByVal Value As DataColumn) As Integer
Value.Parent = Me
Return List.Add(Value)
End Function
Public Sub AddRange(ByVal Value() As DataColumn)
Dim oItem As DataColumn
For Each oItem In Value
oItem.Parent = Me
List.Add(oItem)
Next
End Sub
Public Sub AddRange(ByVal Value As DataColumnCollection)
Dim oItem As DataColumn
For Each oItem In Value
oItem.Parent = Me
List.Add(oItem)
Next
End Sub
#End Region
Public Function Contains(ByVal Value As DataColumn) As Boolean
Return List.Contains(Value)
End Function
Public Sub CopyTo(ByVal array() As DataColumn, ByVal index As Integer)
List.CopyTo(array, index)
End Sub
Public Overloads Function IndexOf(ByVal Value As DataColumn) As Integer
Return List.IndexOf(Value)
End Function
Public Sub Insert(ByVal index As Integer, ByVal Value As DataColumn)
List.Insert(index, Value)
End Sub
Default Public Property Item(ByVal index As Integer) As DataColumn
Get
Return DirectCast(List.Item(index), DataColumn)
End Get
Set(ByVal Value As DataColumn)
List.Item(index) = Value
End Set
End Property
Protected Overrides Sub OnInsert(ByVal index As Integer, _
ByVal Value As Object)
If TypeOf Value Is DataColumn Then
MyBase.OnInsert(index, Value)
DirectCast(Value, DataColumn).Parent = Me
Else
Throw New ArgumentException()
End If
End Sub
Protected Overrides Sub OnSet(ByVal index As Integer, _
ByVal OldValue As Object, _
ByVal NewValue As Object)
If TypeOf NewValue Is DataColumn Then
MyBase.OnSet(index, OldValue, NewValue)
DirectCast(NewValue, DataColumn).Parent = Me
Else
Throw New ArgumentException()
End If
End Sub
Protected Friend Property Parent() As Control
Get
Return _Parent
End Get
Set(ByVal Value As Control)
_Parent = Value
End Set
End Property
Public ReadOnly Property ParentWidth() As Integer
Get
If _Parent Is Nothing Then
Return 0
Else
Return _Parent.ClientSize.Width
End If
End Get
End Property
End Class
|
|
|
|
|
Next, a base for the ComboBox / ListBox:
Imports System.Drawing
Imports System.Windows.Forms
Imports System.ComponentModel
Public Class ComboBoxEx : Inherits ComboBox
'Or - Public Class ListBoxEx : Inherits ListBox
Protected HighlightBrush As Brush
Protected HighlightPen As Pen
#Region "Constructors"
Public Sub New()
DrawMode = DrawMode.OwnerDrawFixed
ItemHeight += 1
HighlightBrush = New SolidBrush(SystemColors.Highlight)
HighlightPen = New Pen(SystemColors.HighlightText)
End Sub
#End Region
#Region "Overrides"
Protected Overrides Sub OnDrawItem(ByVal e As DrawItemEventArgs)
If Not (e.Index = -1) Then
DrawListBoxItem(e)
End If
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
HighlightBrush.Dispose()
HighlightPen.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
<Browsable(False)> _
Public Shadows Property DrawMode() As DrawMode
Get
Return MyBase.DrawMode
End Get
Set(ByVal Value As DrawMode)
MyBase.DrawMode = Value
End Set
End Property
#End Region
#Region "Implementation"
Protected Sub DrawListBoxItem(ByVal e As DrawItemEventArgs)
'
If Enabled AndAlso _
((e.State And DrawItemState.Selected) = DrawItemState.Selected) Then
DrawItemHighlight(e)
Else
DrawItemClearHighlight(e)
End If
DrawItemText(e)
End Sub
Protected Overridable Sub DrawItemText(ByVal e As DrawItemEventArgs)
Dim currentObject As Object = Items(e.Index)
Dim item As String = GetItemText(currentObject)
If Not (item Is Nothing) Then
Dim B As Brush
If Enabled Then
B = New SolidBrush(e.ForeColor)
Else
B = SystemBrushes.ControlDark
End If
e.Graphics.DrawString(item, _
e.Font, _
B, _
New PointF(e.Bounds.Left + 2, e.Bounds.Top))
If Enabled Then B.Dispose()
End If
End Sub
Protected Overridable Sub DrawItemHighlight(ByVal e As DrawItemEventArgs)
Dim g As Graphics = e.Graphics
Dim b As Rectangle = e.Bounds
g.FillRectangle(HighlightBrush, b)
g.DrawRectangle(HighlightPen, b.Left, b.Top, b.Width - 1, b.Height - 1)
End Sub
Protected Overridable Sub DrawItemClearHighlight(ByVal e As DrawItemEventArgs)
e.Graphics.FillRectangle(SystemBrushes.Window, e.Bounds)
End Sub
#End Region
End Class
|
|
|
|
|
Finally, define the List/ComboBox:
Imports System.Drawing
Imports System.Windows.Forms
Imports System.ComponentModel
<DesignerCategory("Component"), _
DefaultProperty("DataSource"), _
TypeConverter("System.Windows.Forms.Design.DataSourceConverter"), _
ToolboxItem(True)> _
Public Class DataComboBoxEx : Inherits ComboBoxEx
'Or - Public Class DataListBoxEx : Inherits ListBoxEx
Private _Columns As DataColumnCollection
Private _GridLineColor As Color
Private _ShowHorizontalGridLines As Boolean
Private _ShowVerticalGridLines As Boolean
Public Sub New()
_ShowVerticalGridLines = True
_ShowHorizontalGridLines = False
_Columns = New DataColumnCollection()
_Columns.Parent = Me
_GridLineColor = SystemColors.ControlDark
ItemHeight = Math.Max(ItemHeight, 22)
End Sub
Protected Overrides Sub DrawItemText( _
ByVal e As System.Windows.Forms.DrawItemEventArgs)
Dim rItem As Rectangle = e.Bounds
Dim g As Graphics = e.Graphics
Dim gPen As New Pen(_GridLineColor)
Dim DS As Object
If DataSource Is Nothing Then
DS = Items
Else
DS = DataSource
End If
Dim rItemF As New RectangleF(rItem.X, rItem.Y, rItem.Width, rItem.Height)
Dim oItem As DataColumn
For Each oItem In _Columns
rItemF.Width = oItem.Width
oItem.OnDraw(e, rItemF, DS, DisplayMember)
If _ShowVerticalGridLines Then
g.DrawLine(gPen, rItemF.Right, rItemF.Y, rItemF.Right, rItemF.Bottom)
End If
rItemF.X += rItemF.Width
Next
If _ShowHorizontalGridLines Then
g.DrawLine(gPen, rItem.X, rItem.Bottom - 1, rItem.Right, rItem.Bottom - 1)
End If
gPen.Dispose()
End Sub
<Category("Behavior"), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public Property Columns() As DataColumnCollection
Get
Return _Columns
End Get
Set(ByVal Value As DataColumnCollection)
_Columns = Value
_Columns.Parent = Me
End Set
End Property
<Category("Appearance")> _
Public Property GridLineColor() As Color
Get
Return _GridLineColor
End Get
Set(ByVal Value As Color)
_GridLineColor = Value
End Set
End Property
<Category("Appearance"), DefaultValue(False)> _
Public Property ShowHorizontalGridLines() As Boolean
Get
Return _ShowHorizontalGridLines
End Get
Set(ByVal Value As Boolean)
_ShowHorizontalGridLines = Value
End Set
End Property
<Category("Appearance"), DefaultValue(True)> _
Public Property ShowVerticalGridLines() As Boolean
Get
Return _ShowVerticalGridLines
End Get
Set(ByVal Value As Boolean)
_ShowVerticalGridLines = Value
End Set
End Property
#Region "Hide properies"
<Browsable(False)> _
Public Shadows Property DropDownStyle() As ComboBoxStyle
Get
Return ComboBoxStyle.DropDown
End Get
Set(ByVal Value As ComboBoxStyle)
MyBase.DropDownStyle = ComboBoxStyle.DropDown
End Set
End Property
<Browsable(False)> _
Public Shadows Property Sorted() As Boolean
Get
Return MyBase.Sorted
End Get
Set(ByVal Value As Boolean)
MyBase.Sorted = Value
End Set
End Property
#End Region
End Class
|
|
|
|
|
Ok, this is good. It will probably take some time for me to evaluate everything here. Will this support "unbound" data as well? Thanks a lot!
|
|
|
|
|
It should do - if you don't specify a data source, it will use the Items property, which implements IList , so it should pick up the items from that.
|
|
|
|
|
hi,
can u send sample code to communicate socketclien in vb and socketserver
in java.
thanks
kavitha
kavitha
|
|
|
|
|
|
I have written 1 app which reads data from access table and
writes it to existing excel sheet .
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open(App.Path & "\ben_aux.xls")
xlBook.Sheets(8).Activate
xlBook.Sheets(8).Name = "MS 2-Nt Rev"
sqlString = "SELECT RESHDR.ArrivalDt as Date, Reshdr.MktSegID, Sum(Reshdr.RoomRev)" _
& "From Reshdr" _
& "Where Reshdr.LOS = 2" _
& "GROUP BY Reshdr.ArrivalDt, Reshdr.MktSegId"
With xlBook.ActiveSheet.QueryTables.Add(Connection:=connstring, _
Destination:=Range("A6"), Sql:=sqlString)
.Refresh
End With
I am getting following error.
the destination range is not on the same worksheet that the query table is being created on.
using VB6.0 and Excel 2000 and access 2000
|
|
|
|
|
Are you simply trying to place the result sets on a worksheet? I wrote a sample of this a while ago, using VB6 + Access w/ Excel.
Check it out:
http://hobbitwerk.brinkster.net/vbSamples/MoreEXcelVBA.zip
*->>Always working on my game, teach me
*->>something new.
cout << "dav1d\n";
|
|
|
|
|
Ya I am executing query and putting result set in to excel sheet .I provide start range for data on excel sheet.
Thanks for ur help....I could write the data on sheet.
1 Question. In query I am calculating Sum and when i am putting the sum on excel sheet I put it like :
sum(abc) as 'xyz'. If i put like sum( abc ) as xyz (w/o single quotes) it gives me error (SQL syntax error ).
|
|
|
|
|
hi
i want to retrive info abt no of print outs taken by diffrent workstation on the network while sitting on server. i have an option to use to a client application at diffrent workstation and server utility at server , so any one could do it locally its ok for me
Work Hard and Test your Luck
|
|
|
|
|
I am trying to write a download manager in VB 6 using the inet control. I am having problems with the proxy though. My company uses an automatic configuration script proxy and the inet control does not seem to recognize it, so it cannot get throught the firewall. I have tried using the built in poxy attributes and functions with no success. Does anyone have any ideas on how to get around this?
Thanks,
Ed
|
|
|
|
|
Hi am something of a newbie I am trying to implement an HTML based help system using and reading it with the webbrowser control in vb6. I would like to generate some of the HTML dynamically (ie search results perhaps with search key highlighted). I can get the webbrowser object to open HTML files I have created. I have writen VB that will generate an HTML "Response", but I do not know how to make the webbrowser control display it. I have considered writing the HTML "Response" to a sequential file and subsequently pointing the webbrowser to the results file. Any help would be greatly appreciated.
Shaggy
|
|
|
|
|
Does anyone know if VB can now (VB6.0) perform a conversion between the internal representation of a single-precision number (held as a long, 4 bytes) and an actual Single? By this I mean, the value 1.0 as a Single = &h3F800000 internally. If I have a Long containing &h3F800000, is it possible to convert to a Single of 1.0, and vice versa (Single -> Long holding internal representation).
So far I have had to use a C DLL to do this.
Other possible ways to do this might involve using Variants, Byte arrays or some way of accessing the memory used to store the variables (used to be VARSEG and VAROFFSET in QuickBasic) - but I can't find a way.
Note that CLng(Single) and CSng(Long) don't do it, since CSng(&h3F800000) = 1065353216.0, which isn't quite 1.0 {:v)
Note also that you can't use Any as the type in your own functions {:v(
If anyone's wondering why I need this, it's to pull bytes out of a Modbus message and decode them, or to encode them and plug them into a message.
|
|
|
|
|
I haven't tested it, but this should work:
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
Public Function Long2Sng(ByVal InVal As Long) As Single
Dim sRet As Single
CopyMemory sRet, InVal, 4
Long2Sng = sRet
End Function
|
|
|
|
|
I can confirm that it does indeed work - no more C DLLs - hurrah!
|
|
|
|
|
Hello there,
Can i edit explorer.exe in such a way that i can change the start button text the vertical image in the start menu and such things. I am using windows 2000 and windows Me
Thanks
|
|
|
|
|
I've changed my start button text, but I can't remember the site that told me how to do it. First, you need to know that the text must be 5 characters long. You can however add a space(s) at the end if you want to put something smaller on it (i.e. Star[space]).
1. Make a copy of explorer.exe and put it somewhere where it won't get touched.
2. It is very important that you follow step 1, otherwise a reinstall of Windows might be required.
3. Open the copy of explorer.exe in a hex editor.
4. Find "53 00 74 00 61 00 72 00 74". That is hex for S[null]t[null]a[null]r[null]t[null]. Some hex editors require the space, and other are the opposite.
5. Replace only the letters with whatever you want. I did "53 00 74 00 65 00 76 00 65 00" = Steve.
6. Now boot from dos and rename your origional explorer to explorer - o.exe or something like that. Then swap the locations of the two explorers.
7. Restart your computer. Either it'll work, or you'll have to go back to dos, swap the explorers back, and start over.
Hope this helps
|
|
|
|
|
one more thing: I know this works on ME, but can't say for sure as to what will hapen for other OS's
|
|
|
|
|
Hello everyone,
Can i add a control panel applet to the control panel through VB, if yes how?
If not in VB then can i do the same in VC++ if yes how ?
Thanks
|
|
|
|
|
How do I activate the OLE component Microsoft Excel Chart at runtime exactly like I have designed it and how do I put new data in to the chart at runtime?
|
|
|
|
|
Pleeeeeease can´t anyone help me with this, it´s breaking me... Men in long white coats will come and get me soon if I dont solve this problem. = (
|
|
|
|
|
It's tricky to make it seem as though *you* were the one who did it. Here's a starting point- you may already be past this:
1. In Excel, start a macro and then create the chart.
2. Examine the code in the macro generated VBA module.
3. Instantiate the Excel.Application, Workbook, Chart and create a chart programmatically using the macro code as your guide.
It isn't difficult to do, but it will require that you users have Excel on their machines.
Oh, and you can macro copy+paste operations too, in case you want to copy it to an OLE container control or something like that.
I hope this puts you on a track...
David
*->>Always working on my game, teach me
*->>something new.
cout << "dav1d\n";
|
|
|
|
|
I'm using VB6. This is probably a beginner question but I created a group of three radio buttons. They are all part of the same control array. However, in runtime mode, when one of the three buttons is clicked on, the old one that was on remains on. Thus, I end up with two radio buttons that are on/enabled. I thought VB handled this automatically. If not, how do I write code to disable/uncheck the other two radio buttons when one is activated?
|
|
|
|
|
VB handles the WS_GROUP style when grouping automatic radio buttons. It groups by "container" controls like a frame, picture box, the main form, etc. If it's not doing it for you then make sure some of the radio buttons are not in a frame, etc. Or put all of them in a frame, etc.
Jeremy Falcon
Imputek
<nobr>"..." - Paul Watson 07-17
|
|
|
|
|