|
well actually the combo box is already an owner drawn one. This is the problem, in my combo box, i set it to owner drawn so the first line of my combo box was bold and underlined - acting as a header. So basically since this first line is acting as a header I don't want the user to be able to select/display that value when they click on it. I had looked in to somehow disabling that first item, but no luck. so i figured i'd cheat and just change the text when they click on it to make it seem that it was disabled. here's my code for the box:
Friend WithEvents ComboBox3 As System.Windows.Forms.ComboBox<br />
Private selectControls() As String<br />
<br />
<br />
Private Sub initializeComboBox()<br />
Me.ComboBox3 = New ComboBox<br />
Me.ComboBox3.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed<br />
Me.ComboBox3.Location = New System.Drawing.Point(10, 20)<br />
Me.ComboBox3.Name = "ComboBox3"<br />
Me.ComboBox3.Size = New System.Drawing.Size(136, 21)<br />
Me.ComboBox3.DropDownWidth = 136<br />
Me.ComboBox3.TabIndex = 0<br />
Me.ComboBox3.DropDownStyle = ComboBoxStyle.DropDown<br />
Me.ComboBox3.Location = New System.Drawing.Point(120, 112)<br />
selectControls = New String() {"Serial Status", "10303 test", "bloop!"}<br />
ComboBox3.DataSource = selectControls<br />
Me.Controls.Add(Me.ComboBox3)<br />
End Sub<br />
<br />
Protected Sub ComboBox3_DrawItem(ByVal sender As Object, _<br />
ByVal e As System.Windows.Forms.DrawItemEventArgs) _<br />
Handles ComboBox3.DrawItem<br />
<br />
Dim size As Single<br />
Dim myFont As System.Drawing.Font<br />
Dim family As FontFamily<br />
<br />
Dim itemColor As New System.Drawing.Color<br />
Select Case e.Index<br />
Case 0<br />
size = 8.25<br />
<br />
itemColor = System.Drawing.Color.White<br />
family = FontFamily.GenericSansSerif<br />
myFont = New Font(family, size, FontStyle.Bold Or FontStyle.Underline)<br />
<br />
Case 1<br />
size = 8.25<br />
itemColor = System.Drawing.Color.White<br />
family = FontFamily.GenericSansSerif<br />
myFont = New Font(family, size, FontStyle.Regular)<br />
Case 2<br />
size = 8.25<br />
itemColor = System.Drawing.Color.Blue<br />
family = FontFamily.GenericSansSerif<br />
myFont = New Font(family, size, FontStyle.Regular)<br />
<br />
End Select<br />
<br />
e.DrawBackground()<br />
<br />
Dim rect = New Rectangle(1, 0, 134, 15)<br />
e.Graphics.FillRectangle(New SolidBrush(Color.Empty), _<br />
rect)<br />
<br />
If e.State = 769 Then<br />
<br />
If e.Index = 0 Then <br />
<br />
e.Graphics.FillRectangle(New SolidBrush(Color.White), _<br />
rect)<br />
<br />
e.Graphics.DrawString(selectControls(e.Index), myFont, System.Drawing.Brushes.Black, _<br />
New System.Drawing.PointF(2, e.Bounds.Top))<br />
<br />
Else<br />
<br />
e.Graphics.DrawString(selectControls(e.Index), myFont, System.Drawing.Brushes.White, _<br />
New System.Drawing.PointF(2, e.Bounds.Top))<br />
End If<br />
<br />
Else<br />
<br />
e.Graphics.DrawString(selectControls(e.Index), myFont, System.Drawing.Brushes.Black, _<br />
New System.Drawing.PointF(2, e.Bounds.Top))<br />
<br />
<br />
End If<br />
e.DrawFocusRectangle()<br />
<br />
End Sub
I'm not too familiar with owner drawn stuff, I can do little stuff like this but real complex stuff i haven't had experience with yet. is there any way to tell it in here to display a different value for the item when it's clicked?
|
|
|
|
|
I am trying to create an autocomplete combobox for a datagrid in vb.net.
I have everything working, except that I cannot force the column to stop when a user presses TAB to enter the column.
I need to allow the user to press tab, and then my datagridcolumn must gain focus, but I cannot figure out how
Anyways, I've attached my code (It's based on some previous articles I have read).
I can get the control to retain focus when TAB is pressed if I put a break-point in the OnEnter(ByVal e as System.EventArgs)
of the NoKeyUpCombo Class, but not without that.
Please help!!!!
Jake
DataGridComboBoxColumn:
<br />
Option Strict Off<br />
Option Explicit On <br />
<br />
Imports Microsoft.VisualBasic<br />
Imports System<br />
Imports System.ComponentModel<br />
Imports System.Data<br />
Imports System.Data.Common<br />
Imports System.Data.OleDb<br />
Imports System.Drawing<br />
Imports System.Windows.Forms<br />
<br />
Namespace DataGridTextBoxCombo<br />
' Step 1. Derive a custom column style from DataGridTextBoxColumn<br />
' a) add a ComboBox member<br />
' b) track when the combobox has focus in Enter and Leave events<br />
' c) override Edit to allow the ComboBox to replace the TextBox<br />
' d) override Commit to save the changed data<br />
Public Class DataGridComboBoxColumn<br />
Inherits DataGridTextBoxColumn<br />
Public WithEvents ColumnComboBox As NoKeyUpCombo<br />
Private _source As System.Windows.Forms.CurrencyManager<br />
Private _rowNum As Integer<br />
Private _isEditing As Boolean<br />
Public Shared _RowCount As Integer<br />
<br />
<br />
Public Sub New()<br />
_source = Nothing<br />
_isEditing = False<br />
_RowCount = -1<br />
<br />
ColumnComboBox = New NoKeyUpCombo<br />
ColumnComboBox.DropDownStyle = ComboBoxStyle.DropDown<br />
<br />
AddHandler ColumnComboBox.SelectionChangeCommitted, AddressOf ComboStartEditing<br />
End Sub 'New<br />
<br />
Private Sub HandleScroll(ByVal sender As Object, ByVal e As EventArgs)<br />
If ColumnComboBox.Visible Then<br />
ColumnComboBox.Hide()<br />
End If<br />
End Sub 'HandleScroll<br />
<br />
Private Sub ComboStartEditing(ByVal sender As Object, ByVal e As EventArgs)<br />
_isEditing = True<br />
MyBase.ColumnStartedEditing(sender)<br />
End Sub 'ComboMadeCurrent<br />
<br />
<br />
Private Sub CompletionCombo_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles ColumnComboBox.Leave<br />
If _isEditing Or ColumnComboBox._isEditing Then<br />
SetColumnValueAtRow(_source, _rowNum, ColumnComboBox.Text)<br />
_isEditing = False<br />
Invalidate()<br />
<br />
End If<br />
ColumnComboBox.Hide()<br />
AddHandler Me.DataGridTableStyle.DataGrid.Scroll, New EventHandler(AddressOf HandleScroll)<br />
End Sub 'LeaveComboBox<br />
<br />
<br />
Protected Overloads Overrides Sub Edit(ByVal [source] As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal bounds As System.Drawing.Rectangle, ByVal [readOnly] As Boolean, ByVal instantText As String, ByVal cellIsVisible As Boolean)<br />
<br />
MyBase.Edit([source], rowNum, bounds, [readOnly], instantText, cellIsVisible)<br />
<br />
'_isEditing = True<br />
_rowNum = rowNum<br />
_source = [source]<br />
<br />
ColumnComboBox.Parent = Me.TextBox.Parent<br />
ColumnComboBox.Location = Me.TextBox.Location<br />
ColumnComboBox.Size = New Size(Me.TextBox.Size.Width, ColumnComboBox.Size.Height)<br />
'ColumnComboBox.SelectedIndex = ColumnComboBox.FindStringExact(Me.TextBox.Text)<br />
ColumnComboBox.Text = Me.TextBox.Text<br />
Me.TextBox.Visible = False<br />
ColumnComboBox.Visible = True<br />
AddHandler Me.DataGridTableStyle.DataGrid.Scroll, AddressOf HandleScroll<br />
<br />
ColumnComboBox.BringToFront()<br />
ColumnComboBox.Focus()<br />
End Sub 'Edit<br />
<br />
<br />
Protected Overrides Function Commit(ByVal dataSource As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer) As Boolean<br />
<br />
If _isEditing Then<br />
_isEditing = False<br />
SetColumnValueAtRow(dataSource, rowNum, ColumnComboBox.Text)<br />
End If<br />
Return True<br />
End Function 'Commit<br />
<br />
<br />
Protected Overrides Sub ConcedeFocus()<br />
Console.WriteLine("ConcedeFocus")<br />
MyBase.ConcedeFocus()<br />
End Sub 'ConcedeFocus<br />
<br />
Protected Overrides Function GetColumnValueAtRow(ByVal [source] As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer) As Object<br />
<br />
Dim s As Object = MyBase.GetColumnValueAtRow([source], rowNum)<br />
Dim dv As DataView = CType(Me.ColumnComboBox.DataSource, DataView)<br />
Dim rowCount As Integer = dv.Count<br />
Dim i As Integer = 0<br />
Dim s1 As Object<br />
<br />
'if things are slow, you could order your dataview<br />
'& use binary search instead of this linear one<br />
While i < rowCount<br />
s1 = dv(i)(Me.ColumnComboBox.ValueMember)<br />
If (Not s1 Is DBNull.Value) AndAlso _<br />
(Not s Is DBNull.Value) AndAlso _<br />
s = s1 Then<br />
Exit While<br />
End If<br />
i = i + 1<br />
End While<br />
<br />
If i < rowCount Then<br />
Return dv(i)(Me.ColumnComboBox.DisplayMember)<br />
End If<br />
Return DBNull.Value<br />
End Function 'GetColumnValueAtRow<br />
<br />
<br />
Protected Overrides Sub SetColumnValueAtRow(ByVal [source] As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal value As Object)<br />
Dim s As Object = value<br />
<br />
Dim dv As DataView = CType(Me.ColumnComboBox.DataSource, DataView)<br />
Dim rowCount As Integer = dv.Count<br />
Dim i As Integer = 0<br />
Dim s1 As Object<br />
<br />
'if things are slow, you could order your dataview<br />
'& use binary search instead of this linear one<br />
While i < rowCount<br />
s1 = dv(i)(Me.ColumnComboBox.DisplayMember)<br />
If (Not s1 Is DBNull.Value) AndAlso _<br />
s = s1 Then<br />
Exit While<br />
End If<br />
i = i + 1<br />
End While<br />
If i < rowCount Then<br />
s = dv(i)(Me.ColumnComboBox.ValueMember)<br />
Else<br />
s = DBNull.Value<br />
End If<br />
MyBase.SetColumnValueAtRow([source], rowNum, s)<br />
End Sub 'SetColumnValueAtRow <br />
<br />
End Class 'DataGridComboBoxColumn<br />
<br />
<br />
End Namespace<br />
NoKeyUpCombo.vb:
<br />
Option Strict Off<br />
Option Explicit On <br />
<br />
Imports Microsoft.VisualBasic<br />
Imports System<br />
Imports System.ComponentModel<br />
Imports System.Data<br />
Imports System.Data.Common<br />
Imports System.Data.OleDb<br />
Imports System.Drawing<br />
Imports System.Windows.Forms<br />
<br />
Namespace DataGridTextBoxCombo<br />
Public Class NoKeyUpCombo<br />
Inherits ComboBox<br />
Private WM_KEYUP As Integer = &H101<br />
Public _isEditing As Boolean = False<br />
<br />
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)<br />
If m.Msg = WM_KEYUP Then<br />
'ignore keyup to avoid problem with tabbing & dropdownlist;<br />
Return<br />
End If<br />
MyBase.WndProc(m)<br />
End Sub 'WndProc<br />
<br />
Protected Overrides Sub OnEnter(ByVal e As System.EventArgs)<br />
_isEditing = True<br />
MyBase.Focus()<br />
End Sub<br />
<br />
Private Sub CompletionCombo_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp<br />
Dim sTypedText As String<br />
Dim iFoundIndex As Integer<br />
Dim oFoundItem As Object<br />
Dim sFoundText As String<br />
Dim sAppendText As String<br />
<br />
If Me.Items.Count > 0 Then<br />
'Allow select keys without Autocompleting<br />
Select Case e.KeyCode<br />
Case Keys.Back, Keys.Left, Keys.Right, Keys.Up, Keys.Delete, Keys.Down, Keys.ControlKey, Keys.ShiftKey, Keys.Alt, Keys.ShiftKey, Keys.MButton, Keys.LButton, Keys.RButton, Keys.Home, Keys.End<br />
'e.Handled = False<br />
Exit Sub<br />
End Select<br />
<br />
'Get the Typed Text and Find it in the list<br />
If Me.Text.Length > 0 And Me.Text.Length <> Me.SelectedText.Length Then<br />
sTypedText = Me.Text<br />
iFoundIndex = Me.FindString(sTypedText)<br />
<br />
'If we found the Typed Text in the list then Autocomplete<br />
If iFoundIndex >= 0 Then<br />
'Get the Item from the list (Return Type depends if Datasource was bound <br />
' or List Created)<br />
oFoundItem = Me.Items(iFoundIndex)<br />
<br />
'Use the ListControl.GetItemText to resolve the Name in case the Combo <br />
' was Data bound<br />
sFoundText = Me.GetItemText(oFoundItem)<br />
<br />
'Append then found text to the typed text to preserve case<br />
sAppendText = sFoundText.Substring(sTypedText.Length)<br />
Me.Text = sTypedText & sAppendText<br />
<br />
'Select the Appended Text<br />
Me.SelectionStart = sTypedText.Length<br />
Me.SelectionLength = sAppendText.Length<br />
'Me.SelectedIndex = iFoundIndex<br />
End If<br />
End If<br />
End If<br />
<br />
End Sub<br />
<br />
Private Sub CompletionCombo_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Leave<br />
Dim iFoundIndex As Integer<br />
<br />
If Me.Items.Count > 0 Then<br />
Dim sFoundText As String = ""<br />
If Me.SelectedText.Length <> Me.Text.Length Then<br />
sFoundText = Me.Text.Substring(Me.SelectedText.Length, Me.Text.Length)<br />
End If<br />
If sFoundText.Length > 0 Then<br />
iFoundIndex = Me.FindString(Me.Text)<br />
<br />
Me.SelectedIndex = iFoundIndex<br />
End If<br />
End If<br />
<br />
' Now ask to make a new address, if there is no autocomplete.<br />
If MyBase.SelectedIndex = -1 And MyBase.Text.Length > 0 Then<br />
If MessageBox.Show("Cannot find item: '" & MyBase.Text & "'." & vbCrLf & "Would you like to create a new item?", "Create a New Entry?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then<br />
' TODO: Add code to make a new inventory item.<br />
Else<br />
MyBase.Text = ""<br />
MyBase.Focus()<br />
End If<br />
End If<br />
End Sub<br />
End Class 'NoKeyUpCombo<br />
End Namespace<br />
<br />
|
|
|
|
|
Create a class module and stick this code in it:
Imports System
Imports System.Data
Imports System.Windows.Forms
Imports System.Drawing
Namespace ComboBoxCode
Public Class DataGridComboBoxColumn
Inherits DataGridTextBoxColumn
Private _comboBox As DataGridComboBox
Private _sorce As CurrencyManager
Private _rowNumber As Integer
Private _editing As Boolean
Public Sub New(ByVal dataSource As DataView, _
ByVal displayMember As String, _
ByVal valueMember As String)
_sorce = Nothing
_editing = False
_comboBox = New DataGridComboBox
_comboBox.DropDownStyle = ComboBoxStyle.DropDownList
_comboBox.Visible = False
_comboBox.DataSource = dataSource
_comboBox.DisplayMember = displayMember
_comboBox.ValueMember = valueMember
AddHandler _comboBox.Leave, AddressOf _comboBox_Leave
AddHandler _comboBox.SelectionChangeCommitted, _
AddressOf _comboBox_SelectionChangeCommitted
End Sub
Public ReadOnly Property ComboBox() As DataGridComboBox
Get
Return _comboBox
End Get
End Property
Private Sub _comboBox_Leave(ByVal sender As Object, _
ByVal e As EventArgs)
If _editing Then
_editing = False
SetColumnValueAtRow(_sorce, _rowNumber, _
_comboBox.Text)
Invalidate()
End If
_comboBox.Visible = False
AddHandler DataGridTableStyle.DataGrid.Scroll, _
AddressOf DataGrid_Scroll
End Sub
Private Sub DataGrid_Scroll(ByVal sender As Object, _
ByVal e As EventArgs)
If _comboBox.Visible Then
_comboBox.Visible = False
End If
End Sub
Private Sub _comboBox_SelectionChangeCommitted( _
ByVal sender As Object, ByVal e As EventArgs)
_editing = True
MyBase.ColumnStartedEditing(CType(sender, Control))
End Sub
Protected Overrides Function GetMinimumHeight() As Integer
Return _comboBox.PreferredHeight
End Function
Protected Overrides Sub SetDataGridInColumn( _
ByVal value As DataGrid)
MyBase.SetDataGridInColumn(value)
_comboBox.Parent = CType(value, Control)
End Sub
Protected Overrides Sub ConcedeFocus()
MyBase.ConcedeFocus()
_comboBox.Visible = False
End Sub
Protected Overloads Overrides Sub Edit( _
ByVal source As CurrencyManager, _
ByVal rowNum As Integer, _
ByVal bounds As Rectangle, _
ByVal [readOnly] As Boolean, _
ByVal instantText As String, _
ByVal cellIsVisible As Boolean)
MyBase.Edit(source, rowNum, bounds, [readOnly], _
instantText, cellIsVisible)
Me.TextBox.Visible = False
_rowNumber = rowNum
_sorce = source
_comboBox.Bounds = bounds
_comboBox.RightToLeft = _
Me.DataGridTableStyle.DataGrid.RightToLeft
If cellIsVisible AndAlso Not [readOnly] Then
_comboBox.Visible = True
_comboBox.BringToFront()
_comboBox.Focus()
End If
_comboBox.SelectedIndex = _
_comboBox.FindStringExact(Me.TextBox.Text)
AddHandler DataGridTableStyle.DataGrid.Scroll, _
AddressOf DataGrid_Scroll
End Sub
Protected Overrides Function Commit( _
ByVal dataSource As CurrencyManager, _
ByVal rowNum As Integer) As Boolean
If _editing Then
_editing = False
SetColumnValueAtRow(dataSource, rowNum, _
_comboBox.Text)
End If
Return True
End Function
Protected Overrides Sub SetColumnValueAtRow( _
ByVal source As CurrencyManager, _
ByVal rowNum As Integer, ByVal value As Object)
MyBase.SetColumnValueAtRow(source, rowNum, _
_comboBox.FindValueMember(value))
End Sub
Protected Overrides Function GetColumnValueAtRow( _
ByVal source As CurrencyManager, _
ByVal rowNum As Integer) As Object
Dim val As Object = _
MyBase.GetColumnValueAtRow(source, rowNum)
Return _comboBox.FindDisplayMember(val)
End Function
End Class
Public Class DataGridComboBox
Inherits System.Windows.Forms.ComboBox
Private WM_KEYUP As Integer = &H101
Protected Overrides Sub WndProc( _
ByRef theMessage As System.Windows.Forms.Message)
If theMessage.Msg = WM_KEYUP Then
Return
End If
MyBase.WndProc(theMessage)
End Sub
Public Function FindValueMember( _
ByVal display As Object) As Object
Dim dv As DataView = CType(DataSource, DataView)
Dim rowCount As Integer = dv.Count
Dim disp As Object
Dim i As Integer
For i = 0 To rowCount - 1
disp = dv(i)(DisplayMember)
If display.Equals(disp) Then
Return dv(i)(ValueMember)
End If
Next i
Return display
End Function
Public Function FindDisplayMember( _
ByVal value As Object) As Object
Dim dv As DataView = CType(DataSource, DataView)
Dim rowCount As Integer = dv.Count
Dim val As Object
Dim i As Integer
For i = 0 To rowCount - 1
val = dv(i)(ValueMember)
If value.Equals(val) Then
Return dv(i)(DisplayMember)
End If
Next i
Return DBNull.Value
End Function
End Class
End Namespace
Then go to where you format your datagrid and use this code for the column you need a datagrid combo box for:
Dim grdColStyle4 As New ComboBoxCode.DataGridComboBoxColumn( _
dvgProducts, "ProductCode", "ProductCode")
''''DataSource, DisplayMember, ValueMember
With grdColStyle4
.MappingName = "ProductCode"
.HeaderText = "Product ID"
.NullText = ""
.Width = 80
End With
You will have to create either a dataview or dataset for your datasource, but this should get you where you want to be.
Let me know how this works out for you.
|
|
|
|
|
Hello everybody,
Trying to develope a small Visual Basic.Net project, I am stucked on one point.
I have a 2.Dimensional Array filling a DataTable. Now I want to build a Diagramm, I don’t want to use an Excel. But every effort to do that doesn’t work.
Here is an example of an Array with the Result of some kind of Formula:
Dim Result(2, 3) As String
For x = 0 To 2
For y = 0 To 3
Result(x, y) = ((x + y) * (y) - x)
Next
Next
Now the Question is kann somebody show me how to build a Diagramm with a Diagramm Scale of (X, Y) using BitMap or Grafics?
Thanx in Advance & Regards
Mickael
|
|
|
|
|
When a user logs in to my web app, I save their login id as Public Shared so that I can reference it later.
Sometimes when it is referenced later, it will grab the login id from someone else's session who is also running the app.
I tried saving the login id as Session("loginid"), it works ok for a while, then it loses it and goes to null.
No messages are coming up saying that the session has been lost, any ideas on what could be wrong or how to fix this would help out a lot.
Thank You!
|
|
|
|
|
partt wrote:
I save their login id as Public Shared
partt wrote:
when it is referenced later, it will grab the login id from someone else's session
That is the correct behaviour - Public Shared mean that all instances of the class will share the same value so it should not be used for storing individual user IDs as a web application is a multi-user system and lots of users will be using it at the same time.
partt wrote:
Session("loginid"), it works ok for a while, then it loses it and goes to null
That is most likely because the session has timed out. There is a setting in the web.config to make the session longer if you need to. The default is 20 minutes, so if the user does not interact with the web application for 20 minutes their session will end so that the server can free up resources to deal with users that are actually using the system. At this point the timed-out user will need to log in again.
Does this help?
Do you want to know more?
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and Forums
|
|
|
|
|
Alright, I'm a beginner in programming, and having the following problems:
/part 1:/
I want to add textboxes dynamically. This happens by an 'Add' button. When I click the 'add button', it adds a textbox below the previous one. But when I activate AutoScroll in the form, the location of the textboxes get all screwed up.
First, this is my code behind the button:
Dim txtTokenName As New TextBox, txtTokenPass As New TextBox
intAantalTokens += 1
txtTokenName.Size = New System.Drawing.Size(150, 20)
txtTokenName.Location = New System.Drawing.Point(80, 25 * intAantalTokens + 30)
txtTokenName.Name = "txtTokenNaam" & CStr(intAantalTokens)
Me.Controls.Add(txtTokenName)
txtTokenPass.Size = New System.Drawing.Size(150, 20)
txtTokenPass.Location = New System.Drawing.Point(250, 25 * intAantalTokens + 30)
txtTokenPass.Name = "txtTokenPass" & CStr(intAantalTokens)
Me.Controls.Add(txtTokenPass)
cmdTokenAdd.Location = New System.Drawing.Point(32, 25 * intAantalTokens + 30)
intAantalTokens is declared globally.
Now, before autoscroll kicks in, everything works perfectly:
http://users.pandora.be/hoflackjp/nanaki/pics/prob1.GIF
When it activates:
http://users.pandora.be/hoflackjp/nanaki/pics/prob2.gif
I checked the location with a MsgBox, and it counts up normal. It just misplaces everything wrong.
/part 2:/ (updated code by now, works with tabcontrol)
I also have a delete button to remove a row of textboxes. This is the code after the previous one. cmdTokenDelete appears right next to the second textbox.
cmdTokenDelete.Size = New Size(16, 16)
cmdTokenDelete.Text = "-"
cmdTokenDelete.Location = New Point(414, 25 * intAantalTokens + 30)
cmdTokenDelete.Name = "cmdTokenDelete" & CStr(intAantalTokens)
Me.tbpTokens.Controls.Add(cmdTokenDelete)
AddHandler cmdTokenDelete.Click, AddressOf TokenDelete
Now, I tried putting everything in TokenDelete(), but it just won't work. I currently have this testing code to delete the 'delete'-button and it doesn't even work:
Private Sub TokenDelete(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim cmdTeVerwijderen As New Button
cmdTeVerwijderen.Name = CType(sender, Button).Name
Me.tbpTokens.Controls.Remove(cmdTeVerwijderen)
End Sub
I would greatly appreciate your help! I've been searching all day and my head hurts. >_<
|
|
|
|
|
I solved the problem with a panel. It's a bug in .net apparently.
But now the second one?
|
|
|
|
|
I have the following line of code that I'm having problems with:
... Privat Sub BtnOK_Click(...)
m_ContractInfo.Strike = txtStrike.Text
I get compile error
"An unhandled exception of type "system.invalidcastexception" occured. Cast from string "" to type double"
Where m_contractInfo.Strike is of type double. I realise the my attempts to assign the value of txtStrike.Text(a String) to m_ContractInfo.Strike(a double) would cause an exception, I just don't know how I can convert between the types.
|
|
|
|
|
try...
m_ContractInfo.Strike = double.parse(txtstrike.text)
-jim
|
|
|
|
|
Thanks Jim, I actually did try that but I still got an error of "Input strin was not in a correct format"
|
|
|
|
|
what's the value of textStrike.Text when you click the button?
-jim
|
|
|
|
|
its a double,
the complete code is:
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
m_OrderID = 0
'Use try catch block to catch error in conversion
Try
m_ContractInfo.Symbol = txtSymbol.Text
m_ContractInfo.SecurityType = txtType.Text
m_ContractInfo.Expiry = txtExpiry.Text
m_ContractInfo.Strike = Convert.ToDouble(txtStrike.Text)
Catch exp As System.FormatException
MessageBox.Show(exp.ToString)
MessageBox.Show(exp.Message)
End Try
m_ContractInfo.Right = txtRight.Text
m_ContractInfo.Multiplier = txtMultiplier.Text
m_ContractInfo.Exchange = txtExchange.Text
m_ContractInfo.PrimaryExchange = txtPrimaryExchange.Text
m_ContractInfo.Currency = txtCurrency.Text
m_ContractInfo.LocalSymbol = txtLocalSymbol.Text
m_OK = True
Me.Close()
' Hide()
End Sub
|
|
|
|
|
then your string plainly cannot be converted to a double. You should pass it through a regex first to make sure the conversion is valid. Better yet, create a textbox that only accepts doubles as valid input.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
I have been trying find tutorials and sample projects that use vb.net to access and manipulated sql 2000 databases but no luck so far. I trying to see how the insert,delet,update,etc. methods are implemented through vb.net
Any help will be appreciated
|
|
|
|
|
|
thx.....never found these sites on google
|
|
|
|
|
I have a very simple ownder drawn combo box in my windows form application. All i'm doing different is making the first items headers with bold and underlined font. I got everything to work great, except for the focus rectangle. at the end of my code i have the e.drawFocusRectangle() method.. it will select the items, but the item font stays black when selected. if you'll notice on a normal combo box (not owner drawn), the items turn white when selected. Can anyone tell me how to do this? Thanks!
p.s. here's my code for the combobox
Private Sub initializeComboBox()<br />
<br />
Me.ComboBox3 = New ComboBox<br />
Me.ComboBox3.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed<br />
Me.ComboBox3.Location = New System.Drawing.Point(10, 20)<br />
Me.ComboBox3.Name = "ComboBox3"<br />
Me.ComboBox3.Size = New System.Drawing.Size(136, 21)<br />
Me.ComboBox3.DropDownWidth = 250<br />
Me.ComboBox3.TabIndex = 0<br />
Me.ComboBox3.DropDownStyle = ComboBoxStyle.DropDown<br />
Me.ComboBox3.Location = New System.Drawing.Point(120, 112)<br />
Me.ComboBox3.Text = "Select Control"<br />
selectControls = New String() {"Serial Status", "10303 test", "bloop!"}<br />
ComboBox3.DataSource = selectControls<br />
Me.Controls.Add(Me.ComboBox3)<br />
End Sub<br />
<br />
Protected Sub ComboBox3_DrawItem(ByVal sender As Object, _<br />
ByVal e As System.Windows.Forms.DrawItemEventArgs) _<br />
Handles ComboBox3.DrawItem<br />
<br />
Dim size As Single<br />
Dim myFont As System.Drawing.Font<br />
Dim family As FontFamily<br />
<br />
Dim itemColor As New System.Drawing.Color<br />
Select Case e.Index<br />
Case 0<br />
size = 8.25<br />
itemColor = System.Drawing.Color.White<br />
family = FontFamily.GenericSansSerif<br />
myFont = New Font(family, size, FontStyle.Bold)<br />
<br />
Case 1<br />
size = 8.25<br />
itemColor = System.Drawing.Color.White<br />
family = FontFamily.GenericSansSerif<br />
myFont = New Font(family, size, FontStyle.Regular)<br />
Case 2<br />
size = 8.25<br />
itemColor = System.Drawing.Color.Blue<br />
family = FontFamily.GenericSansSerif<br />
myFont = New Font(family, size, FontStyle.Regular)<br />
End Select<br />
<br />
e.DrawBackground()<br />
<br />
<br />
e.Graphics.DrawString(selectControls(e.Index), myFont, System.Drawing.Brushes.Black, _<br />
New System.Drawing.PointF(2, e.Bounds.Top))<br />
<br />
<br />
e.DrawFocusRectangle()<br />
End Sub
|
|
|
|
|
I am using USB Card Reader to obtain health card validations string, How can I get the string into a string variable. I don't want it to be displayed into textbox, before showing it to the labels, I want to decode it. I am using this for ASP.Net web forms, Anyone have any suggestions, how to do it?
Thanks in advance
|
|
|
|
|
Your not reading anything from USB. Your reading it from the device itself. USB is just a transport mechanism for the data. Your best bet is to see if the manufacturer puts out a SDK for the card reader. There is no generic method for grabbing data off of any device, not matter what bus it's connected to.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I have created a TreeView (Treeview1) that contains 4 levels. I am trying to create a sub so that when the user clicks the button on the form, The code will cycle through the items that are checked and print their tag properties to a textbox. The For Each statement works fine, but I am having trouble cycling through the children and their children etc. I am still working on the first level of children because it should be the same principle for the rest of the children. Here is what I have so far, although it only prints the tags for the nodes listed in the first For Each statement.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click
Dim node As TreeNode
For Each node In TreeView1.Nodes
If node.Checked = True Then
txtNote.Text = txtNote.Text & node.Tag & vbCrLf
Dim myNodeCollection As TreeNodeCollection = TreeView1.Nodes(node.Index).Nodes
Dim myCount As Integer = myNodeCollection.Count
Dim child1 As Integer
For child1 = 0 To myCount - 1
If TreeView1.Nodes(node.Index).Nodes(child1).Checked = True Then
txtNote.Text = txtNote.Text & TreeView1.Nodes(node.Index).Nodes(child1).Tag & " "
End If
Next
End If
Next node
End Sub
Any assistance would be appreciated.
Thanks.
Marc
|
|
|
|
|
Don't put this code in the button click event. Instead, create a function that takes a TreeNodeCollection as a parameter. This function will enumerate the Nodes in this collection and do your txtNote.Text work, just like you already have. At the same time, you can check each Node to see if it has any children (currentNode.Nodes.Count > 0). If it has children, then the function can call itself, recursively, with a reference to the current node's Nodes collection.
Private Sub Button1_Click(...)
ProcessNodesList( TreeView1.Nodes )
End Sub
.
. ' Warning! Untested code ahead!
.
Private Sub ProcessNodesList(ByRef nodeList As TreeNodeCollection)
Dim currentNode As TreeNode
For Each currentNode In nodeList
If currentNode.Checked = True Then
txtNote.Text += currentNode.Tag & " "
End If
If currentNode.Nodes.Count > 0 Then
ProcessNodesList( currentNode.Nodes )
End If
Next
End Sub
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Actually was just testing a solution that now works, but going to try to understand the recursive thing. Here is what I have for now that works for the first child. Recursive sounds like less code and better performance, but I am still new to some of this.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click
Dim node As TreeNode
For Each node In TreeView1.Nodes
If node.Checked = True Then
txtNote.Text = txtNote.Text & node.Tag & vbCrLf
Dim child1 As TreeNode
For Each child1 In node.Nodes
If child1.Checked = True Then
txtNote.Text = txtNote.Text & child1.Tag & vbCrLf
End If
Next child1
End If
Next node
Addition.................
I tried your code and it works great without having to specify how many levels are present. I may have to use some sort of combination of yours adnd mine, because the first level needs to have a little different formatting like 2 vbcrlf after each of these nodes.
Thanks again for the help
End Sub
I assume the recursive function is better?
Thnks for the help
Marc
|
|
|
|
|
Is there any easy way to just have your function skip the first two levels? I would like to call the function only for the 2nd or 3rd Children and not the root or 1st child. This way I can ensure the formatting I need for the forst two levels. For instance I want one vbcrlf to follow the root, and one to precede and two to follow the first child so the resulting text would look like:
root
Child1
Child2 Child2 Child2
Child1
using the function will format ALL nodes the same. Any suggestions?
Thanks again for the help
Marc
|
|
|
|
|
Then add a second parameter to the function, telling it the level that it's on. Then modify the code that performs the formatting
Private Sub Button1_Click(...)
' Passing in 0 denotes the root of the tree.
' 1 would represent the 1st level of children, or children of the root.
ProcessNodesList( TreeView1.Nodes, 0 )
End Sub
.
. ' Warning! Untested code ahead!
.
Private Sub ProcessNodesList(ByRef nodeList As TreeNodeCollection, ByVal level As Integer)
Dim currentNode As TreeNode
For Each currentNode In nodeList
If currentNode.Checked = True Then
Select Case level
Case 0
' Put whatever formatting you want for level 0
Case 1
' Put whatever formatting you want for level 1
Case 2 To 3
' Put whatever formatting you want for levels 2 and 3
Case 4
' I hop eyou get the idea by now...
End Select
End If
If currentNode.Nodes.Count > 0 Then
' There are children present. Call myself with the new set
' of Nodes and tell myself that this is the next level down
ProcessNodesList( currentNode.Nodes, level + 1 )
End If
Next
End Sub
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|