July 1, 2000

Prevent dragging elements in a ListView control

The ListView control doesn’t expose any property that lets you disable the dragging of its elements. To do so, you must trap the WM_NOTIFY message that the ListView control sends its parent form when the drag operation begins, and “eat” it. Using the MSGHOOK.DLL subclassing library it’s easy to accomplish

Get full control on the text typed in a ListView’s item

The ListView control exposes the AfterLabelEdit event to let the programmer validate the text entered in a ListItem, but there is no way to trap keys as they are typed by the user. This prevents you from discarding unwanted characters while the user types them.You can work around this problem

Bind a group of OptionButtons to a Data control

You can’t directly bind a group of OptionButton controls to a Data control, RDO Data control or ADO Data control. However, you can work around this limitation by adding an hidden TextBox control and add a few lines of code: Private Sub optRadioButton_Click(Index As Integer) ‘ change the contents of

Load items faster in the TreeView and ListView controls

There is an easy, but under-utilized, technique for loading many nodes in a TreeView control (or ListItems in a ListView control) that is faster than the standard technique. Consider this loop: For i = 1 To 5000 TreeView1.Nodes.Add , , , “Node ” & iNext Instead of repeatedly query the

Highlight current word and line in a TextBox control

Here’s a simple way to highlight the current word in a TextBox control (i.e. the word where the caret is): Text1.SetFocusSendKeys “^{LEFT}+^{RIGHT}” Similarly, you can highlight the current line in a multiline TextBox control as follows: Text1.SetFocusSendKeys “{HOME}+{END}” Deleting the current word or the current line is as simple. You

Get the handle of the edit portion of a ComboBox

The ComboBox control contains an invisible Edit window, which is used for the edit area. In most cases you don’t need to access this inner control directly, but occasionally a direct control of that window can be useful. The first thing to do is get the handle of such inner

Updating records in DataList and ADO Data Controls

If you use a DataList control linked to an ADO Data Control and if you want to add a record, you have to create a command button with this code: Private Sub cmdAdd_Click() On Error GoTo AddErr datPrimaryRS.Recordset.AddNew txtNew.SetFocus Exit SubAddErr: MsgBox Err.DescriptionEnd Sub You can specify the new item

Limit the length of an item in a ListView control

The ListView control doesn’t expose any property that lets you limit the amount of text users can type when editing an item’s label. However, you can do the trick with a couple of SendMessage API calls from within the BeforeLabelEdit event: with the LVM_GETEDITCONTROL message you retrieve the handle of

Determine the number of visible items in a ListView control

Microsoft “forgot” to provide the ListView control with the GetVisibleCount property, as it did, for example, with the TreeView control. However, getting this information is as easy as sending a message to the control: Private Const LVM_FIRST = &H1000Private Const LVM_GETCOUNTPERPAGE = (LVM_FIRST + 40)Private Declare Function SendMessage Lib “user32”

No more posts to show