Home | Index | Dotnet4all Snippets | Submit resources
About | Mail us 





Rich Text Box SelectionColor (Tuesday, January 03, 2006)

Found the following interesting discussion in the Newsgroups:

Rich Text Box SelectionColor
by a_poster

I'm making a real-time spell checker that mimics MS Word's real-time spell
checking behavior. As the user types into a rich text box, I detect when a
word has been misspelled and modify the visual appearance of the word in
some way (currently I just turn it red).

So, using a rich text box, I have to :

a) bookmark my current .selectionStart into some integer
b) set .selectionStart to the beginning of the misspelled word
c) set .selectionLength to the end of the misspelled word
d) set .selectionColor = [red]
e) set .selectionStart = bookmarked position

I admit this works - the code's fairly efficient and the PC is fast, so I
can accomplish all this faster than anyone can realistically type and the
user has no idea their selection is running wild all over the textbox every
time they leave a word behind. But I had initially envisioned (not knowing
anything about the rich textbox control) a more elegant system of simply
pointing to a substring in the text and changing it's color, or font or
style or whatever, instantly, and without moving the cursor. Was that a
naive dream or is this possible to do without so much modification to the
selection?


 Reply:
by:Sriram Krishnan

 Your method is the right one (to the best of my knowledge). But you are
right - a more elegant method is necessary. What you say is close to the
way Word does it. It puts properties in property bags and every chunk of
text refers a property bag. So to change the formatting of some text,
you just assign it to some other property bag.

Read Chris Pratley's and Rick Schaut's blog for more details
http://blogs.msdn.com/Chris_Pratley
http://blogs.msdn.com/Rick_Schaut

--
Sriram Krishnan



Posted by Xander Zelders
0 Comments



ListBox non-Dataset load Value and discription

Found the following interesting discussion in the Newsgroups:

ListBox non-Dataset load Value and discription
by:Anonymous

Is there a way to load into a listbox..
one click at a time...
one row at a time...
both a value & display text without using a bound Dataset?
ValueID = 123
DisText = "Bob"
Private Sub btnSplitAdd_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles btnSplitAdd.Click

lbSplitBrkFee.BeginUpdate()
lbSplitBrkFee.Items.Add(ValueID, DisText)
lbSplitBrkFee.EndUpdate()

End Sub

User will only see "Bob", but when they click on the listbox I can get access to the ValueID 123

Thanks
Brian


 Reply:
by:Greg Burns

 cboT1_PayRate.BeginUpdate()
cboT1_PayRate.Items.Clear()

cboT1_PayRate.Items.Add(New ListBoxItem("AN", "Annually"))
cboT1_PayRate.Items.Add(New ListBoxItem("HR", "Hourly"))
cboT1_PayRate.Items.Add(New ListBoxItem("WK", "Weekly"))
cboT1_PayRate.EndUpdate()

....
Public Class ListBoxItem

Private listItemData As Object ' make this whatever datatype most
appropriate for you
Private listItemText As String

' This is what is displayed in the ComboBox drop-down
Public Overrides Function ToString() As String
Return listItemText
End Function

Public Sub New(ByVal itemData As Object, ByVal itemText As String)

listItemData = itemData
listItemText = itemText
End Sub

Public ReadOnly Property Data() As Object
Get
Data = listItemData
End Get

End Property

Public ReadOnly Property Text() As String
Get
Text = listItemText
End Get

End Property

End Class
HTH,
Greg


 Reply:
by:Greg Burns

 forgot to mention; to get value back out, just cast SelectedItem back to
custom ListBoxItem class

Dim PayRateCode as String
PayRateCode=CType(cboT1_PayRate.SelectedItem, ListBoxItem).Data.ToString

news:O$mT6yKVEHA.3024@TK2MSFTNGP09.phx.gbl...
_


 Reply:
by:Anonymous

 Thank you... Workes Great!..

Still don't understand why this is not just part of the LB control.

Oh well it is MS VB.Net ;-D



Posted by Xander Zelders
0 Comments



Knew how to do it the old way, but ...

Found the following interesting discussion in the Newsgroups:

Knew how to do it the old way, but ...
by:Ed Staffin

In vb6, I could load a listbox/combobox with strings and
values using the list and itemdata properties. WHen I
wanted to set the selected item to a value I looked
through the itemdata to find a match.

In vb7, I can't quite seem to figure it out. I can set the
datasource to a datatable, set the display member, set the
value member and have everything display properly.
However, once I have loaded the listbox/combobox with the
data, I can't figure out how to set the selectedIndex
property based on a value I have. I tried looking at the
items collection, but near as I can tell, that thing is
useless. Any guidance would be greatly appreciated.

Thanks ... Ed



 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 

The direct replacement is using custom objects to store additional data:

<URL:http://www.google.de/groups?selm=2hemflFbikgkU2%40uni-berlin.de>
--
Herfried K. Wagner [MVP]


 Reply:
by:Armin Zingler

 
http://groups.google.com/groups?threadm=eniMT6RhDHA.3324@TK2MSFTNGP11.phx.gbl>
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html



Posted by Xander Zelders
0 Comments



InvalidActiveXStateException error when editing simple form elemen

Found the following interesting discussion in the Newsgroups:

InvalidActiveXStateException error when editing simple form elemen
by:Anonymous

I am trying to edit form elements (labels, text box's, etc) in Visual Studio.NET using VB.NET. Whenever I edit certain forms’ appearance whether it is through the code, or through the designer, I receive this (Invalid ActiveX State Exception) error message at runtime whenever the form is called. I am simply trying to change the size and location of some form elements whose location and size were thrown off during the upgrade from VB6.0 to VB.NET. These are not major changes, just a few pixels at most. In addition, after I get this error, the form that I tried to edit is hosed. It throws this runtime error even if I reverse the changes that I made to the form. It is as if something is changing that is not visible. I make sure that everything in the code is changed back to its original state, but still receive this error message. Any suggestions are greatly appreciated.


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 

Just FYI:

Your post is visible in my newsreader, so it has been posted
successfully. No need to post it several times.

According to your problem: What ActiveX controls do you use on the
form? Notice that it's better to use the according Windows Forms
controls instead of the old ActiveX controls if possible.

--
Herfried K. Wagner [MVP]


 Reply:
by:Anonymous

 Yeah, I know - sorry about the excessive posting - I kept receiving an error whenever it attempted to post, so I assumed that it was failing. I have several ActiveX controls that I am currently using. They include Toolbars, Dropdown menus, list views, etc. I have even tried to replace the ActiveX controls with their windows forms equivalent, but when I attempt to replace, I receive the same error. So, I am pretty much stuck using the ActiveX controls until I find a solution.




 Reply:
by:Anonymous

 Yeah, I know - sorry about the excessive posting - I kept receiving an error whenever it attempted to post, so I assumed that it was failing. I have several active x controls that I am currently using. They include Toolbars, Dropdown menus, list views, etc. I have even tried to replace the ActiveX controls with their windows forms equivalent, but when I attempt to replace, I receive the same error. So, I am pretty much stuck using the Active X controls until I find a solution.



Posted by Xander Zelders
0 Comments



when to use DoEvents in vb.net?

Found the following interesting discussion in the Newsgroups:

when to use DoEvents in vb.net?
by:Rich

As I migrate my VB6 apps to vb.net I am checking what
features I need to retain from vb6. In vb6 I noticed that
DoEvents really made a performance difference when I
called it just before a Do/For loop for large datasets. I
hope do some multithreading in vb.net for this. But I am
not completely sure about how

System.Windows.Forms.Application.DoEvents()

works, or its application/purpose. Is this the same as
the DoEvents from vb6? Should I keep this feature in my
vb.net projects?

TIA,
Rich


 Reply:
by:Alex Papadimoulis

 I can't say it any better than the documentation ;-)

events. For example, if you have a form that adds data to a ListBox and add
DoEvents to your code, your form repaints when another window is dragged
over it. If you remove DoEvents from your code, your form will not repaint
until the click event handler of the button is finished executing.

So the answer is, it depends. Do you want messages to be processed (such as
redrawing)? Or do you want to go for maximum performance and not do it?
--
Alex Papadimoulis


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 
There is no 'DoEvents' necessary if you put the dataset processing stuff
into a separate thread.
--
Herfried K. Wagner [MVP]


 Reply:
by:Rich

 Thanks all for your replies. It sounds like

System.Windows.Forms.Application.DoEvents()

is the same as DoEvents from vb6. Just wanted to make
sure.




Posted by Xander Zelders
1 Comments



Playing Audio from a Filestream using MCI

Found the following interesting discussion in the Newsgroups:

Playing Audio from a Filestream using MCI
by:Gidi Morris via .NET 247

Hi,

Is there a way to play audio using MCI (I preffer MCI, but if you know of any others I'll be greatful) from a Filestream?

I mean, I have a filestream to an audio file, can I play the audio? I can't access the file directly, so just using the MCI's MCI_OPEN command won't work.

--------------------------------
From: Gidi Morris


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 

This code should work after doing some changes (reading the byte array
from the filestream instead of loading it from a resource):

<URL:http://www.google.de/groups?selm=c71i55%24gvvlh%241%40ID-208219.news.uni-berlin.de>

--
Herfried K. Wagner [MVP]


 Reply:
by:waw@trfsys.com (Wayde Wyatt)

 hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP]) wrote in message news:<2je97iF10ncdeU6@uni-berlin.de>...

This might be just what you're looking for. A DotNet class wrapper for MCI.

http://www.mentalis.org/soft/class.qpx?id=1

--Wayde



Posted by Xander Zelders
0 Comments



XML in a combobox

Found the following interesting discussion in the Newsgroups:

XML in a combobox
by:alex5772@hotmail-dot-com.no-spam.invalid (tureypr)

Hello Wolrd!

I'm trying to add items. to a comboox from a XML file,

I want to add the parents elements to thre combobox and when you
select an item in the combobox, in a another combobox display the
child elements of the parent element selected.

pleae someone help me


 Reply:
by:One Handed Man \( OHM - Terry Burns \)

 Hi you can create a new DataSet object and real in your data from an XML
file, then you can bind the DataSource and DataMember and DataValue
properties of the combobox to your DataSet.

HTH - OHM
--

OHM ( Terry Burns )


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 

The solution depends on how data is stored in the XML file. Can you
post a sample?

In some cases, the solution posted in the other reply will be the way to
go, in more complicated cases you will have to use classes from the
'System.Xml' namespace ('XmlDocument' etc.).

--
Herfried K. Wagner [MVP]



Posted by Xander Zelders
0 Comments



Setup Project

Found the following interesting discussion in the Newsgroups:

Setup Project
by:Anonymous

I have added a setup project to a solution. The problem is that once it's added, there are no detected dependencies or any other files inside the project. I can build the project to create the .msi, but when I install it, no files are installed. The other project in the solution, which is my windows application works fine in the ide.

Any ideas what might be going on?

Thanks,
Mark


 Reply:
by:tderksen@online.microsoft.com (Todd Derksen [MSFT])

 Mark you are just missing one step.
You need to add the project output(s) of your other projects(s) to your
setup project.
Right click on the setup project and select Add-> Project Output, select
the primary output (for the files built by the project).
You can also add the other outputs if they are needed for your deployment.
I hope that clears things up.

Todd Derksen
--------------------
Visual Basic Deployment Test Team
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
it's added, there are no detected dependencies or any other files inside
the project. I can build the project to create the .msi, but when I
install it, no files are installed. The other project in the solution,
which is my windows application works fine in the ide.



Posted by Xander Zelders
0 Comments



WMI Com Interop exception handling

Found the following interesting discussion in the Newsgroups:

WMI Com Interop exception handling
by:Anonymous

Hi all,

Using WMI I am attempting to catch and exception when doing a managementscope.connect operation.
From the looks of things, this method starts a new worker thread through Interop that then executes the method.
My problem is that regardless of what all I use in my catch statements, the system still raises the
initial dialog reporting the exception. Eventually, my app catches and handles the exception but
I cannot get the initial one. Is there a code snippet somewhere that shows how to hook into the
exception event handler in WMI or Interop? I am purposely running this against a machine that does
not have WMI enabled to ensure that an error will occur. I'm at a loss on how to handle this.
Heres a snip.... and hmmm.. sorry about the formatting....

Public Function blaa() as Boolean
Dim options As New ConnectionOptions()
Dim scope As ManagementScope
Dim blah As String
options.Username = "xxxx\Administrator"
options.Password = "****"
scope = New ManagementScope("\\" & "10.0.1.10" & "\root\cimv2", options)
Try
scope.Connect()
return true
Catch e As System.Management.ManagementException
Return False
Catch e As System.Runtime.InteropServices.COMException
Return False
Catch e As System.Exception
Return False
Catch e As Exception
Return False
End Try
End Function


 Reply:
by:Anonymous

 Anyone have any idea's? I searched over in the Interop forum but havn't seen much. Is this something that I'll need to use reflection for possibly? I'm fairly new to this .Net so I'm not real clear on reflection usage. Btw, I've added handlers for current domain unhandled exceptions and for app threadexceptions and I still can't catch the error.
Thanks to anyone with any ideas ! :)




 Reply:
by:Anonymous

 Anyone have any ideas on this? I've looked over in the interop forum but havn't seen anything jump out at me. I wonder if this is something that I need to use reflection for perhaps? I'm new to this .Net stuff so I'm not realy clear on how that works. BTW, I've added handlers for the current domain and the app thread exceptions and I still can't catch the initial error.

Thanks to anyone with any ideas ! :)



Posted by Xander Zelders
0 Comments



Problem With Mailto Start Process

Found the following interesting discussion in the Newsgroups:

Problem With Mailto Start Process
by:Wayne Wengert

I am using a Sub (see below) to call the default mail application and pass a
list of email addresses and a subject. Most of the time this works perfectly
but occasionally I get an error ("System NullReferenceException: Object
reference not set to an instance of an object"). From what I've been able to
determine, this occurs when there is a username (left of the @) with a
period such as joe.smith@somesite.com). Has anyone seen this type of problem
and have suggestions on how to resolve it?

================ Code =====================
Public Sub StartDefaultMail( _

ByVal [To] As String, _

Optional ByVal Subject As String = "" _

)

Try

Dim psi As New ProcessStartInfo

psi.UseShellExecute = True

psi.FileName = _



Process.Start(psi)

Catch ex As Exception

MsgBox("Exception: " & ex.ToString, MsgBoxStyle.Information, "Error")

Throw _

New Exception( _


ex _

)

End Try

End Sub


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 

Is it possible to get the callstack for the exception?

--
Herfried K. Wagner [MVP]


 Reply:
by:Wayne Wengert

 Herfried;

Is this what you need?

at Microsoft.Win32.NativeMethods.ShellExecuteEx(ShellExeuteInfo info)
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo
startinfo)
at System.Diagnostic.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at OfficeApp.Module1.StartDefaultNail(String To, String Subject) in c:\2005
myProjects\TestApp2\Module1.vb:line 100

Wayne


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 

Yes, but I still don't have an idea.

2005 -- are you using VS 2005 (CTP?)?
--
Herfried K. Wagner [MVP]


 Reply:
by:Wayne Wengert

 Nope - VS Net 2003

Wayne



Posted by Xander Zelders
0 Comments



Comboboxes in windows forms datagrid

Found the following interesting discussion in the Newsgroups:

Comboboxes in windows forms datagrid
by:Anonymous

There is an article with an example on this topic. ( article 323167).
The example works good if the datagrid column is string type. Here is a portion of code that handles text changed:
------------------------------
Private Sub Ctrls_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
If DataGrid1.CurrentCell.ColumnNumber = 3 Then
MyCombo.Visible = False
If DataGrid1.Item(DataGrid1.CurrentCell) & "" = "" Then
SendKeys.Send("*")
End If
DataGrid1.Item(DataGrid1.CurrentCell) = MyCombo.Text
End If
End Sub
---------------------

I have problem to make this work for column with integer type. When I select an integer from the combobox, the screen freezes, error either in SendKeys.Send("*")
or DataGrid1.Item(DataGrid1.CurrentCell) = MyCombo.Text complaining about data type.

Any hits are welcome.

Jenny


 Reply:
by:One Handed Man \( OHM - Terry Burns \)

 This was from Scorp a few days ago

http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q480q

http://www.syncfusion.com/faq/winforms/Files/DataGridBoundCombo_vb.zip

http://dotnet.leadit.be/extendeddatagrid

http://www.knowdotnet.com/articles/kdngrid.html
HTH
--

OHM ( Terry Burns )



Posted by Xander Zelders
0 Comments



Sometimes I want to skip a page - How to do that

Found the following interesting discussion in the Newsgroups:

Sometimes I want to skip a page - How to do that
by: Just Me

In the handler QueryPageSettings I let the user select a "Skip This Page"
option.

But I don't know how to handle it if he does.

I can set a flag and in PrintPage skip printing the page but the page count
in Printer and Faxes still increments.

I can cancel the entire print job but can not find anything that will enable
me to skip one page.
Anyone know how?


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 

Just don't print the page. How to prevent printing strongly depends on
how you handle printing of the pages.

--
Herfried K. Wagner [MVP]


 Reply:
by: Just Me

 
Not sure what you mean. I now in PrintPage only bump my page number variable
and exit.

But the system must consider the fact that PrintPage is entered its a page
(I guess a blank one, I never checked).

Unless someone knows how to tell the system not to add a page to the print
document I'll have to try do it all in QueryPageSettings (but that's not
without a problem). I wish I could in QueryPageSettings or in PrintPage tell
the system not to add this page to the output.

To illustrate the problem think of a 10 page document. For each page, in
QueryPageSettings I ask the user if he want to print the page. Say he does
for the first 9 pages but on page 10 he says not to print page 10. I don't
know what to do. As soon as I exit, PrintPage will get called and if I do
nothing in PrintPage a blank page gets added to the document.
Any ideas how avoid that?



 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 

In 'PrintPage', you can do something like that:

\\Private m_NextPageToPrint As Integer

Private Sub MyPrintDocument_PrintPage(...) Handles ...
Select Case m_NextPageToPrint
Case 1
e.Graphics.DrawString(...)
Case 2
e.Graphics.DrawString(...)
Case 3
...
Case 4
...
End Select
e.HasMorePages = ShouldNextPageBePrinted(...)
End Sub

Private Function ShouldNextPageBePrinted(...) As Boolean
If ... Then
...
m_NextPageToPrint = 4
...
Return True
Else
Return False
End If
End Function
///

--
Herfried K. Wagner [MVP]


 Reply:
by: Just Me

 That looks good. I'd also have to do something in case the first (few)
page(s) are not printed.

Thanks a lot



Posted by Xander Zelders
0 Comments



FxCop Error on command button

Found the following interesting discussion in the Newsgroups:

FxCop Error on command button
by:Eric Sabine

I'm running FX Cop on my assembly and on a form, tons of my labels and
buttons are being flagged with this error. I don't really get the error and
what I am supposed to do to resolve the error. I know that even the form
generated code isn't FxCop "safe" in the 1.1 DNF but apparently 2.0 will be.
Until then... can someone explan to me what needs to be fixed?

The button in this example is a simple one called cmdClear.
thanks
Eric
Error, Certainty 50, for
{
Target : "set_cmdClear(System.Windows.Forms.Button):System.Void"
(IntrospectionTargetMethod)
Resolution : "The method 'set_cmdClear' is an internal, virtual method
defined in public type 'SearchDialog1'. Change the method to be non-virtual,
or secure the type with an inheritance demand for a strong name key that you
own.
Help : "file:
http://www.gotdotnet.com/team/fxcop/docs/rules/SecurityRules/InternalVirtualMbrs.html "
(String)
RuleFile : "SecurityRules.dll" (String)
Info : "When internal virtual members exist on a public type running on
version 1.0 of the .NET Framework, subclasses
can overwrite the internal virtual member, possibly creating an exploitable
security weakness."

More Info : "Callers might assume that they are accessing a member that is
defined internally, when the code being executed is actually defined in a
subclass of the type. Even though the 'internal' keyword is present on the
virtual member, on version 1.0 of the .NET framework this subclass
can be located in a different assembly. If the caller asserts permissions
before accessing the overridden member, the member code could run with
elevated permissions. Also, callers that make decisions based on data
returned by the member might be vulnerable to attack. While the assembly
containing the subclass must have access to the defining type in order to
override its members,the 'internal' key word is not, by itself, sufficient
to prevent this access. If you do not fix a violation of this rule, be sure
to review all code that calls this method to ensure any information returned
by the vulnerable member is being used safely."
Created : "6/17/2004 3:29:23 PM" (DateTime)
LastSeen : "6/17/2004 4:14:58 PM" (DateTime)
Status : Active (MessageStatus)


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 

Sure you read <URL:http://www.gotdotnet.com/team/fxcop/docs/rules/SecurityRules/InternalVirtualMbrs.html>?

Maybe marking the method as 'NotOverridable' helps, but this should be
done automatically if the method doesn't override a base class
procedure. Another solution would be to change the modifier of the
members to 'Private' or 'Protected', or to simply ignore what FxCop
says.

--
Herfried K. Wagner [MVP]


 Reply:
by:Eric Sabine

 Marking the label, i.e, Private WithEvents ThisLable as
System.Windows.Forms.Lable, with Private does the trick. Thanks.
Eric




Posted by Xander Zelders
0 Comments



How to scroll down on listView (programmatically)

Found the following interesting discussion in the Newsgroups:

How to scroll down on listView (programmatically)
by:Anonymous

Hi,
How do I scroll down to an item in ListView control based on selection made from another window.
Any Help will be appreciated
Thanks
Al



 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 
Call the ListViewItem's 'EnsureVisible' method.
--
Herfried K. Wagner [MVP]


 Reply:
by:Anonymous

 Herfried Many Thanks!



Posted by Xander Zelders
0 Comments



Open a file save as byte

Found the following interesting discussion in the Newsgroups:

Open a file save as byte
by:Nicolas

How do I open a file which is saves into the database as byte()

So far, I got this and it's working

Dim myDoc as Byte()
myDoc = CType(dbDataRow("Document"), Byte())

From there how do I open this so the user can review this file.

Thank for the help.


 Reply:
by:Drew Berkemeyer

 ' Convert the byte array to a string

Dim ascii As ASCIIEncoding = new ASCIIEncoding();

Dim strText As String = ascii.GetString(myDoc);


 Reply:
by:Greg Young

 Do you know the type of data in your byte array or the original file name ?

if so you could just write your byte array out to a temp file and then use
Process.Start(tempfilename) so long as it has the correct extension and it
is mapped in windows.


 Reply:
by:Nicolas

 So I should Save the Type of the file within the database right.
and then how do you go to create the file (byte array out to a temp file)
because i don't know if it is a text or graphic or media file

Thank again


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 

You will have to save it to disk using 'System.IO.FileStream' and then
use 'System.Diagnostics.Process.Start' to open the file.

--
Herfried K. Wagner [MVP]



Posted by Xander Zelders
0 Comments



How to add a property to an inherited tool?

Found the following interesting discussion in the Newsgroups:

Adding a property to an inherited tool
by:Tom

I'm making a new class: "validatedTextBox" which is based
on the textBox tool. I need to add several properties to
it that can be set in the properties window of the IDE
when I put the new textbox on a form. I have figured out
how to do this, but would like to know how I can make one
of these properties have a drop-down list in the
properties window that gives just the few valid choices
for the property
(e.g. "integer", "real", "date", "phonenumber")

Thanks


 Reply:
by:Ken Tucker [MVP]

 Hi,

Use an enum. Here is an example.
Public Enum DrawWidth
Thin = 2
Normal = 5
Wide = 8
End Enum
Public Property LineWidth() As DrawWidth
Get
Return mLineWidth
End Get
Set(ByVal Value As DrawWidth)
mLineWidth = Value
Invalidate()
End Set
End Property

Ken


 Reply:
by:Jay B. Harlow [MVP - Outlook]

 Tom,
The easiest way is to make that property a Enum

Public Enum ValidChoice
Integer
Real
Date
PhoneNumber
End Enum

Public Class ValidatedTextBox
Inherits TextBox

Public Property ValidChoice() As ValidChoice
Get ...
Set ...
End Property

End Class

For more advanced features check out the following articles:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/usingpropgrid.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/vsnetpropbrow.asp

Hope this helps
Jay


 Reply:
by:Tom

 Thank you. Your solutions worked perfectly.

By the way, as this is the first time I've written into a
discussion forum I am unsure of the etiquette. (I have
searched and read them for many years.) Is writing a thank
you proper, or am I just adding unnecessary extra traffic
to the forum?


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 

It's always nice to hear a thank you ;-).

--
Herfried K. Wagner [MVP]



Posted by Xander Zelders
0 Comments



Retrieve Domain Names

Found the following interesting discussion in the Newsgroups:

Retrieve Domain Names
by:Anonymous

All,

I need to be able to retrieve a list of Domains that are part of our network: similar to the list you get when you log onto a Windows station that is part of a domain.
I assume that I can get this via Active Directory but being somewhat new to that I am not sure where it is or how to get at it.
Any help is appreciated. Thanks!

Dan


 Reply:
by:scorpion53061

 Answer provided by Mr. Ken Tucker. Let me know if it helps.

Hi,

This will only work if you are connected to an active directory. Add
a reference to system.directoryservices. Replace NetworkName with your
network name.

Dim de As New
System.DirectoryServices.DirectoryEntry("LDAP://NetworkName")

Dim ds As New System.DirectoryServices.DirectorySearcher(de)

Dim r As System.DirectoryServices.SearchResult

ds.Filter = "(objectClass=computer)"

Try

For Each r In ds.FindAll

Dim s As String

Console.WriteLine(r.GetDirectoryEntry.Name.ToString)

Next

Catch e As Exception

Console.WriteLine(e.ToString)

End Try
This NetServerEnum api will work for a network without a domain. I
pasted the code for a sample console app below.

Imports System.Runtime.InteropServices

Module Module1

Structure Computer_info_101

Public Platform_ID As Integer

<MarshalAsAttribute(UnmanagedType.LPWStr)> Public Name As String

Public Version_Major As Integer

Public Version_Minor As Integer

Public Type As Integer

<MarshalAsAttribute(UnmanagedType.LPWStr)> Public Comment As String

End Structure

Declare Unicode Function NetServerEnum Lib "Netapi32.dll" _

(ByVal Servername As Integer, ByVal level As Integer, _

ByRef buffer As Integer, ByVal PrefMaxLen As Integer, _

ByRef EntriesRead As Integer, ByRef TotalEntries As Integer, _

ByVal ServerType As Integer, ByVal DomainName As String, _

ByRef ResumeHandle As Integer) As Integer

Declare Function NetApiBufferFree Lib "Netapi32.dll" _

(ByVal lpBuffer As Integer) As Integer

Private Const SV_TYPE_SERVER As Integer = &H2 ' All Servers

Sub Main()

Dim ComputerInfo As Computer_info_101

Dim i, MaxLenPref, level, ret, EntriesRead, TotalEntries, ResumeHandle
As
Integer

Dim BufPtr As Integer

Dim iPtr As IntPtr

MaxLenPref = -1

level = 101

ret = NetServerEnum(0, level, BufPtr, MaxLenPref, EntriesRead,
TotalEntries,
_

SV_TYPE_SERVER, "MSHOME", ResumeHandle) ' Replace MSHOME with your
workgroup
name

If ret <> 0 Then

Console.WriteLine("An Error has occured")

Return

End If

' loop thru the entries

For i = 0 To EntriesRead - 1

' copy the stuff into our structure

Dim ptr As IntPtr = New IntPtr(BufPtr)

computerInfo = CType(Marshal.PtrToStructure(ptr,
GetType(Computer_info_101)), _

Computer_info_101)

BufPtr = BufPtr + Len(ComputerInfo)

Console.WriteLine(computerInfo.Name)

Next

NetApiBufferFree(BufPtr)

Console.Write("Press Enter to End")

Dim s As String = Console.ReadLine()

End Sub

End Module


 Reply:
by:Armin Zingler

 
There's no VB.Net command for this. Maybe you'll get an answer in one of the
..Net Framework groups: microsoft.public.dotnet.framework.*
--
Armin




Found the following interesting discussion in the Newsgroups:

Retrieve Domain Names
by:Anonymous

All,

I need to be able to retrieve a list of Domains that are part of our network: similar to the list you get when you log onto a Windows station that is part of a domain.

I assume that I can get this via Active Directory but being somewhat new to that I am not sure where it is or how to get at it.

Any help is appreciated. Thanks!

Dan


 Reply:
by:scorpion53061

 Answer provided by Mr. Ken Tucker. Let me know if it helps.

Hi,

This will only work if you are connected to an active directory. Add
a reference to system.directoryservices. Replace NetworkName with your
network name.

Dim de As New
System.DirectoryServices.DirectoryEntry("LDAP://NetworkName")

Dim ds As New System.DirectoryServices.DirectorySearcher(de)

Dim r As System.DirectoryServices.SearchResult

ds.Filter = "(objectClass=computer)"

Try

For Each r In ds.FindAll

Dim s As String

Console.WriteLine(r.GetDirectoryEntry.Name.ToString)

Next

Catch e As Exception

Console.WriteLine(e.ToString)

End Try
This NetServerEnum api will work for a network without a domain. I
pasted the code for a sample console app below.

Imports System.Runtime.InteropServices

Module Module1

Structure Computer_info_101

Public Platform_ID As Integer

<MarshalAsAttribute(UnmanagedType.LPWStr)> Public Name As String

Public Version_Major As Integer

Public Version_Minor As Integer

Public Type As Integer

<MarshalAsAttribute(UnmanagedType.LPWStr)> Public Comment As String

End Structure

Declare Unicode Function NetServerEnum Lib "Netapi32.dll" _

(ByVal Servername As Integer, ByVal level As Integer, _

ByRef buffer As Integer, ByVal PrefMaxLen As Integer, _

ByRef EntriesRead As Integer, ByRef TotalEntries As Integer, _

ByVal ServerType As Integer, ByVal DomainName As String, _

ByRef ResumeHandle As Integer) As Integer

Declare Function NetApiBufferFree Lib "Netapi32.dll" _

(ByVal lpBuffer As Integer) As Integer

Private Const SV_TYPE_SERVER As Integer = &H2 ' All Servers

Sub Main()

Dim ComputerInfo As Computer_info_101

Dim i, MaxLenPref, level, ret, EntriesRead, TotalEntries, ResumeHandle
As
Integer

Dim BufPtr As Integer

Dim iPtr As IntPtr

MaxLenPref = -1

level = 101

ret = NetServerEnum(0, level, BufPtr, MaxLenPref, EntriesRead,
TotalEntries,
_

SV_TYPE_SERVER, "MSHOME", ResumeHandle) ' Replace MSHOME with your
workgroup
name

If ret <> 0 Then

Console.WriteLine("An Error has occured")

Return

End If

' loop thru the entries

For i = 0 To EntriesRead - 1

' copy the stuff into our structure

Dim ptr As IntPtr = New IntPtr(BufPtr)

computerInfo = CType(Marshal.PtrToStructure(ptr,
GetType(Computer_info_101)), _

Computer_info_101)

BufPtr = BufPtr + Len(ComputerInfo)

Console.WriteLine(computerInfo.Name)

Next

NetApiBufferFree(BufPtr)

Console.Write("Press Enter to End")

Dim s As String = Console.ReadLine()

End Sub

End Module

news:BF431D7D-2D13-4309-AAEA-E2FAEE2CC78A@microsoft.com:



 Reply:
by:Armin Zingler

 
There's no VB.Net command for this. Maybe you'll get an answer in one of the
..Net Framework groups: microsoft.public.dotnet.framework.*
--
Armin





Posted by Xander Zelders
0 Comments



listView + events

Found the following interesting discussion in the Newsgroups:

listView + events
by:Won Lee

How come there isn't an event handler for when an item or subitem of a
listview changes?



 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 

Subitems cannot edited directly by the user, so there is no need for
such an event. As a programmer, you should know yourself when you
change the text if a subitem.

--
Herfried K. Wagner [MVP]


 Reply:
by:Won Lee

 

Ahh ok. That makes sense. Except I have need to call a method which
calls another form. It works fine when I call the methods in any other
method but specific datastream handler that I'm using. I can't actually
see the code for the datastream event handler because I'm referencing a
DLL.

I'm not sure why it's happening. It doesn't seem to be fixable from my
side. I need to move the method call to another part of the app. I was
hoping that I could add an event handler on the subitems but that
doesn't seem to work. I did try to also select the item when I add the
subitem.

Dim li As ListViewItem

ListView1.SelectedItems.Clear()
For Each li In ListView1.Items
If li.Text = symbol Then
li.SubItems.Add("X")
li.Selected = True
Console.WriteLine("selected: " & li.Text)
Exit For
End If
Next li
Private Sub ListView1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
Console.WriteLine("selectedIndexChanged1")
Try
Console.WriteLine("subitem" &
ListView1.SelectedItems.Item(0).SubItems(0).Text)
If ListView1.SelectedItems.Item(0).SubItems(0).Text = "X" Then
Console.WriteLine(ListView1.SelectedItems.Item(0).Text)

Console.WriteLine(ListView1.SelectedItems.Item(0).SubItems(0).Text)
CallAlertBox(ListView1.SelectedItems.Item(0).Text)
End If

Catch ex As Exception
Console.WriteLine(ex)
End Try

End Sub

But I'm getting an array out of bounds error



Posted by Xander Zelders
0 Comments



RTC and VB.NET

Found the following interesting discussion in the Newsgroups:

RTC and VB.NET
by:KS

Has someone tried RTC and VB ?

Some sample code - please

KS, Denmark


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 

What's RTC?

--
Herfried K. Wagner [MVP]



Posted by Xander Zelders
1 Comments



How to change an image?

Found the following interesting discussion in the Newsgroups:

How to change an image?
by:Miguel Dias Moura

Hello,

i know how to hide a table according to a condition:
<table runat="server" visible='<%# dataSetBibliotecas.FieldValue("Titulo",
Container) <> "" %>'...

Now I am trying to change the image file as follows:
- Show the image "yes.gif" if the value of a dynamic field is equal to
- Show the image "no.gif" if the value of a dynamic field is equal to "NO".

Do you think this is possible? Can you help me out?

Thank You,
Miguel


 Reply:
by:Cor Ligthert

 Hi Miguel.

You multipost in a lot of groups and does not follow up the previous
messages, do you want to be so kind to crosspost next time, than we can see
what where the answers in the other groups.

crossposting sending one message to more newsgroups with a comma to seperate
them.

Thanks,

Cor


 Reply:
by:Miguel Dias Moura

 Hi,

when i cross post is not with the rude intention.

I use 4 foruns:
microsoft.public.dotnet.languages.vb
microsoft.public.dotnet.languages.aspnet
macromedia.dreamweaver.appdev
www.asp.net

The reason is simple: when i make a question in only one of these foruns i
allways get an answer but it doesn't mean that is the best solution
So when i post in the 4 foruns i allways get different aproaches which helps
me much more.
Not everybody goes to all these 4 foruns so this way i allways get different
answers and ideas from people working in different ways.

Anyway, i will do as you asked me and post all the messages with the same
post so people as you that visit them all can check it out.

Thank You,
Miguel





Posted by Xander Zelders
0 Comments



Q: Names of worksheets in ExcelQ: Names of worksheets in Excel

Found the following interesting discussion in the Newsgroups:

Q: Names of worksheets in Excel
by:Geoff Jones

Hi

Can anybody tell me how to get the names of the worksheets in an Excel file
without creating an Excel object i.e. Excel itself may not be on the machine
using the application which looks at the Excel files.

Thanks in advance

Geoff


 Reply:
by:Paul Clement

 
You can use GetOleDbSchemaTable to retrieve the Excel Worksheet names:

Dim DatabaseConnection As New System.Data.OleDb.OleDbConnection
Dim SchemaTable As DataTable

DatabaseConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=e:\My Documents\Book10.xls;Extended Properties=Excel 8.0;"

DatabaseConnection.Open()

SchemaTable =
DatabaseConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, _
New Object() {Nothing, Nothing, Nothing, Nothing})

Dim RowCount As Int32

For RowCount = 0 To SchemaTable.Rows.Count - 1
Console.WriteLine(SchemaTable.Rows(RowCount)!TABLE_NAME.ToString)
Next RowCount

DataGrid1.DataSource = SchemaTable

DatabaseConnection.Close()
Paul


 Reply:
by:Geoff Jones

 
Properties=Excel 8.0;"
DatabaseConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tab
les, _
Console.WriteLine(SchemaTable.Rows(RowCount)!TABLE_NAME.ToString)

Many thanks Paul

Goeff



Posted by Xander Zelders
0 Comments



 
Previous Posts
    - Rich Text Box SelectionColor
    - ListBox non-Dataset load Value and discription
    - Knew how to do it the old way, but ...
    - InvalidActiveXStateException error when editing si...
    - when to use DoEvents in vb.net?
    - Playing Audio from a Filestream using MCI
    - XML in a combobox
    - Setup Project
    - WMI Com Interop exception handling
    - Problem With Mailto Start Process

Archives
    - 08/01/2004 - 08/08/2004
    - 08/08/2004 - 08/15/2004
    - 08/15/2004 - 08/22/2004
    - 08/22/2004 - 08/29/2004
    - 08/29/2004 - 09/05/2004
    - 09/05/2004 - 09/12/2004
    - 09/12/2004 - 09/19/2004
    - 09/19/2004 - 09/26/2004
    - 09/26/2004 - 10/03/2004
    - 10/03/2004 - 10/10/2004
    - 01/02/2005 - 01/09/2005
    - 01/09/2005 - 01/16/2005
    - 01/30/2005 - 02/06/2005
    - 01/01/2006 - 01/08/2006


Disclaimer & Terms of Use | DotNet4All.Com concept & © 2004 - 2007 by Zelders² - Holland