June 2004 - Posts
Paul Vick just posted the results of his survey and I made the top of the list:
http://www.panopticoncentral.net/archive/2004/06/18/1291.aspx
I am blushing now, thanks to all for the votes.
This is a small example of how you can use an Extender Provider to set a controls Visibility, or Enabled, or ReadOnly, etc Property:
http://dotnetrocks.blogspot.com/archives/2004_06_20_dotnetrocks_archive.html#108810524780218376
see my Thursday, June 24 3:25pm entry
The example is based on a Roles model and sets these properties based on which roles a user is in.
Credits to Francesco Balena for this.
I think this is a bug.
See an example of this at http://dotnetrocks.blogspot.com/ Thursday, June 24, 2004 entry.
I have a DataTable that contains 10 DataRows.
Lets call it "names".
I have a textbox on a form bound to the "names.enddate" field\datacolumn.
Me.TextBox1.DataBindings.Add("Text", ds, "names.enddate")
The first DataRow does not have a value for enddate.
The 2nd DataRow does.
When I run the app, the textbox displays the Text set at Design Time ("This
is my test" in my example)
Me.TextBox1.Location = New System.Drawing.Point(120, 56)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.TabIndex = 3
Me.TextBox1.Text = "This is my test"
If I move to the next record by adding 1 to the Position
Me.BindingContext(ds, "names").Position += 1
I see the value for enddate in the textbox for the 2nd DataRow.
If I move back to the first DataRow
Me.BindingContext(ds, "names").Position -= 1
I no longer see "This is my test", I see a blank textbox, which is what I should see.
When I first run the app I should not see "This is my test" in the textbox, I should see an empty textbox.
See an example of this at http://dotnetrocks.blogspot.com/ Thursday, June 24, 2004 entry.
Here's a snippet that may help:
#Region " Enable\Disable a Form's Close Button "
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Integer, ByVal revert As Integer) As Integer
Private Declare Function EnableMenuItem Lib "user32" (ByVal menu As Integer, ByVal ideEnableItem As Integer, ByVal enable As Integer) As Integer
Private Const SC_CLOSE As Integer = &HF060
Private Const MF_BYCOMMAND As Integer = &H0
Private Const MF_GRAYED As Integer = &H1
Private Const MF_ENABLED As Integer = &H0
Public Sub DisableFormCloseButton(ByVal form As System.Windows.Forms.Form)
' The return value specifies the previous state of the menu item (it is either
' MF_ENABLED or MF_GRAYED). 0xFFFFFFFF indicates that the menu item does not exist.
Select Case EnableMenuItem(GetSystemMenu(form.Handle.ToInt32, 0), SC_CLOSE, MF_BYCOMMAND Or MF_GRAYED)
Case MF_ENABLED
Case MF_GRAYED
Case &HFFFFFFFF
Throw New Exception("The Close menu item does not exist.")
Case Else
End Select
End Sub
Public Sub EnableFormCloseButton(ByVal form As System.Windows.Forms.Form)
EnableMenuItem(GetSystemMenu(form.Handle.ToInt32, 0), SC_CLOSE, MF_BYCOMMAND)
End Sub
#End Region
Credits to the source that helped me figure this out.
I started reading "Object Thinking" this week. If you've got $30 laying around, buy it. Its an interesting read.
"Better tools, methods, and processes will allow you to create superior software using average human resources." Now that is a money statement; one I never took the time to think of or about.
"Their <managers> distrust of human workers led them to the idea that imposed process and method could compensate for weakness they felt to be innate in workers."
"The best programmers are up to 28 times better than the worst programmers.....Given their pay is never commensurate, they are the biggest bargains in the software field."
So, I think I need to get out of this industry now as I am one of those 'worst' programmers... ;-)
Seriously though, how do you measure best to worst?
Food for thought.
I build all day long. Suddenly, the build tells me a type has no constructors and sends me here:
Dim frmSearch As New frmNameSearch(True, current)
If I change frmNameSearch's BuildAction from Compile to None to Compile, the error goes away. What the? Or, if I delete my bin\obj folders for frmNameSearch, it goes way, though on the next build it tells me I have errors when there are none. I build again and its happy.
The joke on our team when this happens: "would somebody please define some damn constructor for frmNameSearch!"
Try this out. Create a windows application. Drag 2 textboxes onto the form. Leave the default Text.
Handle the first textboxes validating event. If it's Text is empty, set CancelEventArgs.Cancel to True AND show a messagebox.
Run adn do something in TextBox1 that causes Cancel to get set to True. You should see the MessageBox.
Notice that Textbox2's GotFocus event is not suppressed. It should be IMHO.
Now, try the same test, this time use an ErrorProvider instead of a MessageBox:
Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
If Me.TextBox1.Text.Trim.Length = 0 Then
e.Cancel = True
Me.ErrorProvider1.SetError(Me.TextBox1, "Oops")
End If
End Sub
Private Sub TextBox2_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox2.GotFocus
MessageBox.Show("got focus")
End Sub
GotFocus is suppressed in this case. Interesting.
Just curious. The docs state:
"Reset Supported by the .NET Compact Framework.
Much of the list has changed. Any listening controls should refresh all their data from the list. "
So, how much is much? ;-)
Try this out:
Create a UserControl. Drag a button onto it. Set the button's CausesValidation property = False.
Create a Form. Drag the UserControl you just created onto this Form.
Build this form as a dll.
Create another Form. Inherited from the first form. Drag a textbox onto this inherited form.
Put a breakpoint in the textbox's validating event handler.
Run
Click on the textbox, then click on the button. Why does the textboxes validating event fire? It should not as the button's CausesValidation property is set to False.
It looks like the UserControls child controls' .CausesValidation properties are ignored & whatever's set at the UserControl level controls is used.
When the Merge or AcceptChanges methods are called on a DataSet, the DataSet notifies all the DataViews bound to it that they must reset the list they are handling and the DataView notifies this to all the bound controls.
For a bound control, a reset must be treated as if the data after the reset is completely different than the data previously presented.
If you are working with a list, a grid for example, you may see the selected row change to another row (the first one in the DataTable) if you call AcceptChanges on DataSet.
The recommended way to avoid this behavior in bound controls is NOT to use the Merge method of a DataSet and use the ImportRow method of the table and then do the merge in each of the rows that will be merged in order to prevent the Reset.
So instead of calling AcceptChanges in the DataSet, call AcceptChanges only in those DataRows that were updated.
More Posts
Next page »