|
This is a snippet for when I fill an unbound datagrid. The row is appended at the bottom of the dgv.
_poItemDT.Rows.Add(New Object() { _
_curPOMaterial.Id, _
Double.Parse(txtOrderQty.Text).ToString("#,##0.000"), _
_curPOMaterial.UOM, _
_curPOMaterial.MaterialName, _
_curPOMaterial.Decsription, _
Double.Parse(txtSalePrice.Text).ToString("0.0000"), _
(CDbl(txtOrderQty.Text) * (CDbl(txtSalePrice.Text))).ToString("0.0000")})
Edit - on further reflection (and without seeing your code) I guess you are creating a DataGridViewRow and then adding that to the DataGridView. I would create a DataTable as above, populate the DataTable's rows, and then set the DGV.DataSource = dt
I don't speak Idiot - please talk slowly and clearly
'This space for rent'
Driven to the arms of Heineken by the wife
|
|
|
|
|
Hi,
I am trying to get a program, created in visualbasic.net 2008 on a windows xp computer, to work on a computer with windows 2000 installed on it. Is this possible?
Thanks!
|
|
|
|
|
Sure, just install the .NET Framework you wrote the app against and install your app.
|
|
|
|
|
|
|
Is there any way to detect selected text in another window. As a example there is a form with a text box and it's minimized in the system tray. When a user select a text in a window or another program(like word, excel etc.) that minimized form should appear and selected text should place in the text box. If this is possible, please someone give me an idea to do this.
|
|
|
|
|
Asked and answer many times.
There is no reliable method to detect text being selected in every application. You'd have to write methods for generic methods you could TRY on selected apps, but there is nothing that will work in all cases. Also, there are apps where no matter what you do you couldn't detect this at all.
|
|
|
|
|
Yes, this is possible in most circumstances.
The first problem is in identifying which window you care about. Multiple applications can have text selected at the same time. You can make clever use of FindWindow() and FindWindowEx() to get a handle to the window in question.
The second problem is in identifying the GUI element on that window that might have text that you are interested in. This is actually a much more complicated problem since the GUI element could be any sort of object, nested anywhere on the window. You could use GetWindow() to help with this.
The third problem is telling what text is selected within that GUI element. The way you do this depends on the GUI element in question. In a few cases, it may not even be possible. I'm not really sure where I would begin to try to crack that nut.
There are a ton of useful API calls that you can use at http://msdn.microsoft.com/en-us/library/ff468919%28v=VS.85%29.aspx[^]
You might almost be better off thinking about this problem differently. You could, for example, set up some global system hooks to capture the relevant mouse and keyboard events that occur when text is selected. Then, you would have immediate and direct insight into the objects with which you were dealing. Read this article for an idea of where to start with that approach: Global System Hooks in .NET[^]
Good luck.
|
|
|
|
|
Hi, dear all,
I have several textbox in my form.
Among them there are two have dependency.
For example (not same but the idea is same), user need to input name, age and action.
I add Leave event for age textbox, if age < 18 years old, the action dropdown box will be disabled.
Everything is fine if I move to other control after input age, the action dropdown box will be enable/disabled at once I leave the textbox.
My problem is that if I input age and didn't click other control in the form, instead I click the form itself, the Leave event won't get fired, so the action dropdown box cannot be updated (enable or disable).
What should I do to always have the Leave event fired?
Thanks!
|
|
|
|
|
Andraw Tang wrote: What should I do to always have the Leave event fired?
Leave the textbox?
More seriously, if you check you will see that if a textbox has the focus, when you click on the form, the box does not lose focus.
So you need to detect the click on the form, and if the textbox currently has focus then leave it.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
David,
Thanks for your reply.
Yes, you are right, even we click the form, the textbox still has focus. I have several textbox, how can I detect which one is focused? do you have some example about it?
|
|
|
|
|
|
Also if I put these textbox in a Groupbox in a form, when you click the Groupbox, the form.click won't be fired, in this case Do I need to right click event for all these container?
|
|
|
|
|
Write a single eventhandler, and hook up all the events that need be handled. Means one actual implementation, and the other handlers pointing to that implementation.
I are Troll
|
|
|
|
|
Would you please give me an example how to use it?
Thanks!
|
|
|
|
|
Using code only;
Public Partial Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
Dim b As New Button()
b.Parent = Me
b.Location = New Point(0, 0)
Controls.Add(b)
Dim c As New CheckBox()
c.Parent = Me
c.Location = New Point(0, 0 + b.Height)
Controls.Add(c)
AddHandler b.Click, New EventHandler(AddressOf MyDragEventHandler)
AddHandler c.Click, New EventHandler(AddressOf MyDragEventHandler)
End Sub
Private Sub MyDragEventHandler(sender As Object, e As EventArgs)
System.Diagnostics.Debug.WriteLine(sender.ToString() & " iz clicked")
End Sub
End Class
Or, if you want to do it from the IDE, try these steps;
- Drag a button and a checkbox to the form
- Go to the properties of the button, and switch to "events" view (button looks like lightning)
- Double-click on the
Click event, and write your code
- Go back to the designer, and select the checkbox
- Properties, events-view; there's a combobox next to the
Click event - open it, and select the item "Button1Click"
That should do it
I are Troll
|
|
|
|
|
Thank you very much for your code.
But sorry I didn't fully get it.
If I create a GroupBox1 in Form1, and add textBox1, textBox2 and textBox3 to the GroupBox1, textBox3 is dependent to textBox1 (updated in textBox1_Leave).
then I hook up these controls to MyDragEventHandler, for example I click textBox1, MyDragEventHandler handler will be called. then I input data to textBox1, if I don't click textBox2 or textBox3, instead, I click form or GroupBox1, the cursor is still in textBox1, the dependency of textBox3 cannot be updated since textBox1_Leave is not fired.
If my understanding is wrong, please point it out. very appreciate.
|
|
|
|
|
Your understanding is correct. A groupbox doesn't receive focus when you click it, and TextBox1 is still the active control. (The cursor is still blinking in that textbox, right?)
The Leave event is fired when the input-focus changes within your application. That happens when the user clicks a button, or moves the cursor to some other textbox. There's no way to indicate that someone is "finished" with typing in a textbox except for waiting until the focus moves away.
FWIW, you can set the ActiveControl property to Nothing if the user presses the enter-key.
What functionality are you trying to achieve? If you want to validate the contents of the input, that has it's own event. Take a look here[^] at the order in which events are fired, perhaps there's another way to achieve what you want
I are Troll
|
|
|
|
|
Eddy,
What I try to acheve it that:
If user input negative value, the textBox3 will be disabled, otherwise, textBox3 is enabled.
So if I input negative value to textBox1, but didn't click other controls, the textBox1_Leave not fired, then the textBox3 is still enabled.
Normally how you handle this case of case?
|
|
|
|
|
Andraw Tang wrote: Normally how you handle this case of case?
I'd go for the Validating event, with code similar to below;
1 Public Partial Class MainForm
2 Inherits Form
3 Private t As New TextBox()
4 Private t2 As New TextBox()
5
6 Public Sub New()
7
8 t2.Parent = Me
9 t2.Location = New Point(0, 0)
10
11
12 t.Parent = Me
13 t.Location = New Point(0, 0 + t2.Height)
14
15 Controls.AddRange(New Control() {t, t2})
16
17
18 AddHandler t.Validating, New CancelEventHandler(AddressOf t_Validating)
19 End Sub
20
21 Private Sub t_Validating(sender As Object, e As CancelEventArgs)
22
23 Dim senderAsTextBox As TextBox = TryCast(sender, TextBox)
24
25
26 Dim IsContentValid As Boolean = senderAsTextBox.Text.Contains("-")
27
28
29 e.Cancel = IsContentValid
30
31
32
33 t2.Enabled = Not IsContentValid
34
35
36 If IsContentValid Then
37 System.Media.SystemSounds.Beep.Play()
38 End If
39 End Sub
40 End Class
That will allow the user to switch to another program (to lookup the correct value on the internetz, for example), but it won't allow the user to do anything (like clicking a button in your program or closing it) until the textbox has a valid value.
To achieve what you requested, remove line #29.
I are Troll
|
|
|
|
|
Eddy,
Thank you very much, I will try tomorrow and let you know the result.
|
|
|
|
|
You're welcome, and sleep well
|
|
|
|
|
leave event is fired only when ur focus is left from that control
|
|
|
|
|
Yes, when focus only leave the control when I click other control, do you know how can I let focus leave control when I click other place instead of control on the form?
Thanks!
|
|
|
|
|
I'm trying to delete a file on a remote server using VB.Net and the File.Delete method but I get an Access Denied Exception. I have full Admin rights to the server and file in question and I have no issues deleting the file using windows explorer. I can also delete files and folders on the server, it's just files in one particular folder that causes the issue, and no the file does not appear to be in use.
The code looks something like this...
Imports System.IO.File
Imports System.IO
if file.exists(path) then
try
file.delete(path)
msgbox("File Deleted")
catch ex as exception
msgbox("Unable to Delete File!")
end try
else
msgbox("File Doesn't Exist!")
end if
Please Help.
|
|
|
|
|