|
As Dave has already pointed out, adding text by appending what is already there to the new text will create a new copy of the entire text. I believe RichTextBox has an AppendText (or Append ) method that will edit the text in memory and update the UI.
SelectionStart is set twice, once should be enough.
If RichTextBox supports BeginUpdate and EndUpdate , use them. It will speed up UI refresh.
|
|
|
|
|
Hi,
I need help in writing a script for outlook 2003.
This is what i want the script to do for me..
1.) I want the script to run outlook and select a mentioned profile,
2.) Then the script should be able to minimize the outlook window,
3.) After that I need to do send & receive,
4.) And in the last, script should be able to close the outlook properly.
Can anyone help..?
Presently I am using a scripts to run outlook do send and recieve and then close it...
Its working fine the only problem is I am using sendkey(F9) to do send and receive and it only works if outlook window is active.
And plus I want add one more thing, I should also be able to minimize the outlook with this script so that it wont bother other’s when they logon to the computer.
My prsent Script is
<package>
<job id="vbs">
<script language="VBScript">
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "outlook /profile registration"
WScript.Sleep 20000
WshShell.AppActivate "Outlook"
WScript.Sleep 1000
WshShell.SendKeys "{F9}"
WScript.Sleep 28000
Dim oOL 'As Outlook.Application
Set oOL = GetObject(, "Outlook.Application")
If oOL Is Nothing Then
'no need to do anything, Outlook is not running
Else
'Outlook running
oOL.Session.Logoff
oOL.Quit
End If
Set oOL = Nothing
</script>
</job>
</package>
|
|
|
|
|
I came across something that I thought was kind of odd. My software does data analysis on a bunch of data and there is a function that determines what kind of data point each point is. To do this the function looks at different fields to try and determine it. For example:
Select Case value
Case value.contains("reading")
Case value.contains("cal")
Case Else
End Select
Recently one of the data points sent to this determination function (value ) was exactly "cal". In this case when the value was evaluated in the select statement it wasn't picked up. I need to change the select statement to:
Select Case value
Case value="cal"
Case value.contains("reading")
Case value.contains("cal")
Case Else
End Select
Is this always how the contains methods worked? That if the string was exactly the same as the parameter passed to the contains method that the contains method would return false? I just recently migrated this project to .NET 4 and VS2010, but I'm pretty sure that in .NET 3.5 and VS2008 the first select statement would have worked. Did something change in .NET 4 with how the contains statement is evaluated?
|
|
|
|
|
It's not the Contains method that has the problem. It's your use of the Select Case/Case statements.
The Select Case statement cannot be used the way you're using it. Select Case <testexpression> must evaluate to a elementary datatype, which gets compared to the values listed in the Case statements.
You're putting the testexpressions in the Case statements, which will not work.
The way you're written your code, none of the Case statements should execute, except whats in the Case Else block.
Nothing about Select Case has changed. It's worked the exact same way since .NET 1.0.
Try it yourself on any version of VB.NET:
Dim source As String = "Something"
Select Case source
Case source.Contains("Some")
Console.WriteLine("Some: True")
Case source.Contains("Something")
Console.WriteLine("Something: True")
End Select
Select Case source.Contains("Something")
Case True
Console.WriteLine("Select 2: Contains 'Something' is True")
Case Else
Console.WriteLine("Select 2: Else")
End Select
Console.WriteLine("String 'Something' contains 'Something': " & source.Contains("Something"))
|
|
|
|
|
Nice catch
Don't you think VB compiler should flag an error when it is asked compare string with a bool? May be Option Strict On would do that.
|
|
|
|
|
I'm using VB Express 2010.
This is my scenario: a form shows records one by one from a datatable via a bindingsource. One of the field is showed in a combobox whose items come from a second datatable (lookup datatable), defined in the same dataset of the first one and with a datarelation between them.
So I have a second bindingsource with datasource set to the dataset and datamember set to lookup datatable; this bindingsource is the datasource of the combobox.
Now, I don't want all the records from the lookup datatable to be showed in the combobox everytime, but only a subset which comes from filtering the lookup bindingsource accordingly to other selections the user make in the form. There are mainly two different situation to be managed to reach this behavior:
- when the user changes other fields relevant for filtering combobox's items during record editing
- when a different record is selected changing main bindingsource position.
I wrote the following code in order to reach the goal:
Private FilterComboBoxDataSource()
' Variable to store actual SelectedItem from LookUp BindingSource
Dim t As DataRowView = Nothing
' Variable to store actual ItemID value from Main BindingSource
Dim i as Integer = -1
' Stores the current row from Main BindingSource as a typed DataRow from Main DataTable
Dim r As MainRow = CType(CType(Me.MainBindingSource.Current, DataRowView).Row, MainRow)
' Stores actual UpdateMode for every Binding of the ComboBox DataBinding Collection
' and changes it to DataSourceUpdateMode.Never
' (At moment only one binding exists, that for SelectedValue)
Dim updateModes As Dictionary(Of BindingMemberInfo, DataSourceUpdateMode) =
New Dictionary(Of BindingMemberInfo, DataSourceUpdateMode)
For Each b As Binding In Me.ItemIDComboBox.DataBindings
updateModes.Add(b.BindingMemberInfo, b.DataSourceUpdateMode)
b.DataSourceUpdateMode = DataSourceUpdateMode.Never
Next
' If ItemID isn't Null, searches related record in LookUp BindingSource underlying DataTable and stores it
' (Should use IsNull Function of untyped DataRow because ItemID is a NonNull Field)
If Not r.IsNull("ItemID") Then
Dim dv As DataView = CType(Me.LookUpBindingSource.List, DataView).Table.DefaultView
dv.Sort = "ID ASC"
t = dv(dv.Find(r.ItemID))
' Stores ItemID value - needed because t couldn't be find, so ItemID will be used to relocate the record - See below
i = r.ItemID
End If
' Set up Filter for LookUp BindingSource
' Field1, Field2 and Field3 are fields from Main DataTable whose values are displayed, via Main BindingSource,
' in three CheckBoxes on the form
Me.LookUpBindingSource.Filter =
String.Format("Field1 = {0} And Field2 = {1} And Field3 = {2}",
Me.Field1CheckBox.Checked,
Me.Field2CheckBox.Checked,
Me.Field3CheckBox.Checked)
' If an item was previously selected in ComboBox (t is not nothing)
' tries to find and reselect it in the ComboBox by setting the position
' of filtered LookUp BindingSource
' IT DOESN'T WORK: IndexOf(t) always returns -1. Why?
If Not IsNothing(t) Then
Me.TipiMovimentoBindingSource.Position =
Me.TipiMovimentoBindingSource.IndexOf(t)
End If
' If an item was previously selected in ComboBox (i > -1)
' tries to find and reselect it in the ComboBox by setting the position
' of filtered LookUp BindingSource
' THIS WORKS
If i > -1 Then
Me.TipiMovimentoBindingSource.Position =
Me.TipiMovimentoBindingSource.Find("ID", i)
End If
' Reset DataSourceUpdateMode for each binding of ComboBox
For Each b As Binding In Me.IDTipoComboBox.DataBindings
b.DataSourceUpdateMode = updateModes(b.BindingMemberInfo)
Next
updateModes = Nothing
End Sub
This Sub is called from the CheckedChanged event handlers of field1, field2 and field3 checkboxes, which are the fields the filter is based on, and accomplish filtering caused by user interaction on these field; everything works fine.
The sub is also called from main BindingSource.CurrentChanged event handler, so that the combobox shows only those items related to actual values of field1, field2 and field3 when a different record become the current one, and here is where the issue arises.
Given that the binding to the main bindingsource for SelectedValue Property of the combobox has DataSourceUpdateMode set to OnPropertyChanged, as I need an immediate push back of the selected value, I first switch it to Never, store the current value for the field from the main source, filter the lookup datasource, try to locate the correct item basing on ItemID value in main source and, finally, turn back DataSourceUpdateMode to previuos setting. This way I should have no changes in the record due to filtering operation, and in fact at the end of the Sub the row related to the record is Unchanged and dataset HasChanges returns false.
However, when the position in the main bindingsource changes, it turns out that the row is modified in the ItemID field, the one bound to the combo box, though its value is the same as the original one, and dataset HasChanges returns true.
This occurs not for all records, but only when the new current record has a different combination of field1, field2 and field3 values than the previous one. So it seems that when main BindingSource position changes, it happens something like this:
- combo box items are those filtered for previous record basing on its field1, field2 and field3 values
- if the combination of field1, field2 and field3 values is the same for new current record, IDItem from main BindingSource finds a correspondance in the item list of the combobox
- however, if the combination of these fields is different, IDItem couldn't find a correspondance. At this point, lookup BindingSource Position doesn't reflect IDItem value in main BindingSource
- next, main BindingSource.CurrentChanged event is triggered and FilterComboBoxDataSource is invoked
- here is performed the filtering for new values and lookup BindingSource Position is set to the item corresponding to IDItem value in main BindingSource
If this is what appears to happens, how can I intercept changes in main BindingSource position so that I can filter lookup ComboBox before the newly selected record becomes the current one?
On the other side, given that the record is unmodified before and after the call to FilterComboBoxDataSource, it seems tha program flow is correct. Why the record is modified when the position in main BindingSource changes? It seems that it's a problem of the framework that sees a changes in ItemID field during filtering, ignoring the setting of DataSourceUpdateMode to Never.
At the end I've got a record which appear to be changed, but it's not true and for me is a problem because I want to track only changed records.
Any idea about how to solve this problem?
Thanks in advance
Stefano
|
|
|
|
|
It seems I found a solution.
Instead of trying to relocate the actual item by setting LookUpBindingSource Position after having filtered it, if I reread the value of ItemID from MainBindingSource inside its CurrentChanged event and everything works fine.
This is the complete code
Private Sub MainBindingSource_CurrentChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MainBindingSource.CurrentChanged
Me.FilterComboBoxDataSource()
Me.ItemIDComboBox.DataBindings("SelectedValue").ReadValue()
End If
End Sub
Private FilterComboBoxDataSource()
Dim updateModes As Dictionary(Of BindingMemberInfo, DataSourceUpdateMode) =
New Dictionary(Of BindingMemberInfo, DataSourceUpdateMode)
For Each b As Binding In Me.ItemIDComboBox.DataBindings
updateModes.Add(b.BindingMemberInfo, b.DataSourceUpdateMode)
b.DataSourceUpdateMode = DataSourceUpdateMode.Never
Next
Me.LookUpBindingSource.Filter =
String.Format("Field1 = {0} And Field2 = {1} And Field3 = {2}",
Me.Field1CheckBox.Checked,
Me.Field2CheckBox.Checked,
Me.Field3CheckBox.Checked)
For Each b As Binding In Me.IDTipoComboBox.DataBindings
b.DataSourceUpdateMode = updateModes(b.BindingMemberInfo)
Next
updateModes = Nothing
End Sub
Hope it's useful.
Stefano
|
|
|
|
|
I have a dropdown List
whose ID = 2.1, 2.2, 2.3 .....
If I do Me.txtItemNumber.Text = ddlKeyResultsMeaures.SelectedValue.ToString()
it just read 2 not 2.1 or 2.2 etc
Could u please hepl me in this
|
|
|
|
|
Why are you calling ToString() on the SelectedValue [^], since it is already a string?
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Me.txtItemNumber.Text = ddlKeyResultsMeaures.items(ddlKeyResultsMeaures.Selectedindex)
try this
|
|
|
|
|
Hello,
I saw this code of developer we have doing something at my company and he's using the word "shared" in front of routines everywhere. For example, he has a dll that he's referencing from a website and lots of routines in the dll are coded "shared". These routines aren't doing simple formatting or soemthing that, they are doing DB work, etc. Is there a concern in how many times a shared routine can be called currently? I personally do not like his design at all and i'm curious what everyone else's opinions are about the usage. Is using shared in this way a lazy thing or ?
Any opinions are appreciated (within this topic - ha ha).
Thanks
Nathan
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
|
|
|
|
|
For starters, Shared is over-used.
You can (and should) use Shared on methods that perform a state-less operation, e.g. mathematical functions Math.Abs and Math.Sin
You could have a Shared method that say increments a counter inside a database, provided the whole operation is contained in the method.
And you can create a class that is entirely Shared (all its data members and methods are Shared) provided it represents a unique object, something you are sure you never will need more than one instance of. Not too many real-life objects would fill that description though, most things aren't unique (although they may start of as a unique instance, e.g. your app may currently have access to only one database, however that might change in the future).
|
|
|
|
|
Thanks Luc,
So if he has a routine that accepts 1-n arguments that could be different per call and does a search and update from/to a database - not a good candidate for a shared routine - correct or? Is there a limit to how many current calls can be made to a shared routine?
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
There is no limit on the number of threads that can call a static method at the same time.
Actually, any limit that does come up would be imposed by the design and coding of the code calling these methods and the data passed in. But, in general, there is no limit but the ones you impose yourself.
|
|
|
|
|
Thanks Dave,
Do you object to a design that seems to be flooded with "shared" use?
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
Yeah, it sounds as though it's way over-used. Those methods sound like they should be moved to an instance of a data layer.
|
|
|
|
|
nlarson11 wrote: not a good candidate
depends. Does the code need state? Or is it all self-contained, i.e. execute and forget?
nlarson11 wrote: Is there a limit to how many current calls can be made to a shared routine?
No more than for a non-Shared method. Again, see Math.Sin()
|
|
|
|
|
self-contained. ok good to know.
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
A Shared (static) method does not interact with the class it's defined in. Anything in your class that doesn't touch instance-members can be made shared.
Sometimes a procedural programmer will have trouble thinking in OO, generating lots of static methods that take lot's of parameters.
The OO-way makes it's handy to have all the parameters and other variables embedded in an object, and interact with those, each "group" of procedures becoming objects;
shared Sub MySBSOpener(sbs as Object, HowMany as integer, ByRef TestCount as Integer)
shared Sub MySBSTester(sbs As Object, HowOften as integer, Verbose as Boolean)
shared Sub MySBSCloser(sbs as Object, Title as String, ByRef TestCount as Integer, Verbose as Boolean)
Class SBS
private _howMany as int
private _howOften as int
Public Sub New(HowMany as Integer, HowOften as Integer)
_howMany = HowMany
_howOften = HowOften
End Sub
public Sub MyOpener()
public Sub MyTester()
public Sub MyCloser(Title As String)
public property Verbose as Boolean
public readonly property TestCount
get
return _testCount
end get
end property
End Class
This has the advantage that you can populate a list with these things, something that's a bit harder to do if all methods are static.
Bastard Programmer from Hell
|
|
|
|
|
thanks Eddy
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
You're welcome
|
|
|
|
|
I have dymanuc drop down generated controls ( in some cases I can have as many as 5,3.... or none).
If I have 3 drop downs then first needs to be enable and after they select 1 second and so on. How would I do this witout post back?
Currently I am adding
AddHandler ddlGroupStudentTypes.SelectedIndexChanged, AddressOf ddlGroupStudentTypesValueChanged
|
|
|
|
|
If your dropdowns are truly dynamic, then you are going to have to make a request from the server to get the next dropdown's values. In the most technical sense, that is a post to the server. I assume that you mean that you don't want to do a page refreshing style of a postback. In other words, you want an ajax call to load the data for the next dropdown.
You have two general schools of thought you can go with:
1. UpdatePanel. This lets you run things through your server side events, and it disguises the postbacks so they don't make the page refresh. Pros are that it is simpler to implement. You basically can implement it as you would if you wanted the dropdowns to do a postback to load the next one. Then you wrap the dropdowns in an update panel, and set a few things and you are done. The update panel makes all those postbacks become ajax calls that don't refresh the page.
Cons are that it is far less efficient in terms of bandwidth and server resources, and it can lead to some difficult debugging if you aren't familiar with the .net life cycle. Update panels result in a massive amount of auto generated javascript and additional markup being rendered to the browser which is not really ideal. Also, update panels only work for web forms applications, and are not available for MVC. I assume from what I saw in your question that you are doing web forms.
2. Ajax calls to web methods. Pros are that this is clean and efficient. You save tons on bandwidth consumption which can be a big deal for slow connection users. You also take a much lighter load on the server resources, which is a big deal for higher traffic solutions. You also are in much better control of what is rendered to the browser. Cons are that you have to know javascript a lot better than you would with update panels, and you have to take care of a few specifics that update panels abstract or take care of for you.
I vastly prefer the 2nd option. If you go with the ajax option, then I can give you some additional pointers and things to look out for. I would suggest you use jquery and set up something like:
in javascript:
$("#myDropDown1Id").change(function(){
$.ajax({...//look at jquery.com for your specifics. You set your address, and send your parameters
success:function(data){
//receive the data from your server and populate dropdown2
},
error:function(data){
//notify the user in some way
});//end of .ajax
});//end of change function
Then you need to have a function exposed to be called as a web service. In web forms, you can have a method on your code behind and annotate the method as a WebMethod, or you can add a web service to the project and have methods exposed there. The json parameters you pass in javascript must match the case of your parameters on the server side exactly, which can be a gotcha. Order of the parameters is also important I believe.
If you do it via an ajax call then your web forms code behind won't have wired up change events for your dropdown. Rather you have web methods exposed that take a value and return data to the client.
The other thing to look out for on web forms is that if you are building dropdowns client side, the web forms security will get mad at you when you do finally submit. You will get an error that your values weren't registered for postback. It is webforms effort to prevent malicious javascript from injecting invalid options into the values a dropdown can send back.
To fix that you need to call a registerforpostback method associating every value you send back in your web service with that dropdown. That one can be a pain to work the nuances out.
So there is a lot involved, and I obviously didn't give you a full explanation on every aspect. I hope I gave enough that you can google for details and get it working. Good luck.
|
|
|
|
|
I am inheriting my own datagridview (say MyDataGridView) from the standard datagridview control. What I want is that certain properties of MyDataGridView should have a different default value than what its base have. For example,
AllowUserToAddRows, AllowUserToDeleteRows, AllowUserToResizeRows properties should have the default values of False; so that when I drag MyDataGridView into a form in the IDE, the default values shown in the properties grid should be False.
Later on, if I want to change them to True from the grid, they will be set accordingly. Is it possible somehow? Please note that I don't want to set the default value of any custom property in MyDataGridView but the properties mentioned
above that are derived from the base.
Thanks.
VS.Net, Framework 4.0, VB.Net, C#.Net, WinForms
|
|
|
|
|
Have a try of this
Public Class Class1
Inherits DataGridView
Private _AllowUserToAddRows As Boolean = False
Public Shadows Property allowUserToAddRows() As Boolean
Get
Return _AllowUserToAddRows
End Get
Set(ByVal value As Boolean)
If _AllowUserToAddRows <> value Then
_AllowUserToAddRows = value
MyBase.AllowUserToAddRows = value
End If
End Set
End Property
End Class
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
modified 12-Jan-12 10:58am.
|
|
|
|
|