|
I have an app where I have a parent and child form. How can I capture the key that is pressed (if any) on the child form? I tried the keydown method, but when I run the program, it will not enter the method when I type a key.
Any help would be appreciated. Thanks.
|
|
|
|
|
the 2 forms are completely independent of each other even though you started one from another. event or delegate is the proper way to go.
the event example(done by memory - syntax is mostly good)
public class form1
private withevents mForm2 as form2
private sub ChildKeyDown(sChar as string) handles mForm2.ChildKeyDown
msgbox("the key pressed was: " & sChar
end sub
'add logic to show form2
end class
public class form2
event ChildKeyDown(sChar as string)
private textbox1_keydown(sender , e ) handles textbox1.keydown
raiseevent childkeydown(e.keychar)
end sub
end class
'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
|
|
|
|
|
Just wanted to say thanks for this post - this is an area that is new to me and you have answered a question I had. 5 Stars
Guy
You always pass failure on the way to success.
|
|
|
|
|
hi
we are currently making a website, we also have a client in vb.net
the client works like gtalk where the user has to log in..
the same username and password will apply to the website and the client
is there anyway that we can post values/data from the client to the website, but it needs to be specific to the username provided by the user
in other word, what ever is uploaded from the client must go directly to the webpage of the specific user
any help would be most appreciated
thanks
|
|
|
|
|
I'd recommend developing a webservice to which your client app. 'talks'...
|
|
|
|
|
I'm using the SaveFileDialog in VB.NET 1.1 and would like to perform some processing if the user has clicked yes to overwritting an existing file but I cant seem to be able to catch this. I have tried to use something like (If SaveFileDialog.ShowDialog = DialogResult.Yes Then) but I cant seem to hit this condition at all. Any help please!
JojoStoneHead
|
|
|
|
|
Have you tried using DialogResult.OK ?
I hope this helps.
|
|
|
|
|
thanks but DialogResult.OK is only hit if the file does not exist and the over write dialog is not displayed. However when the overwrite dialog is displayed the buttons displayed are Yes/No and after accepting to overwrite I cant hit DialogResult.OK or DialogResult.Yes
|
|
|
|
|
The following code works fine for me, even if the file exists and I press Yes to the Overwrite Prompt.
If sfd.ShowDialog = Windows.Forms.DialogResult.OK Then<br />
MsgBox("Save Done")<br />
End If
Which version of Visual Basic are you using? I suppose if worse comes to worse, you could disable the Overwrite Prompt property and do a manual check whether the file exists or not, IO.File.Exists(SaveFileDialog.FileName) , and then proceed from there.
|
|
|
|
|
Hi,
IMO you worry too much.
this is the behavior I expect: when you choose the destination file and it
- either does not exist
- or it exists but you allow for an overwrite,
then the SaveFileDialog will return a go-ahead result (I think it's OK),
and your code should open the file for writing in such a way that it does not
matter whether it already exists or not, such as:
- File.Create() which creates new, or overwrites without appending
- File.CreateText() which creates new, or overwrites without appending
The above would work fine, except in one special case, that's when the file already exists
but is set to read-only (not checked by SaveFileDialog).
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
for the existing MenuStrip-Item I want to create an appropriate ToolStrip with identical buttons.
But how can I access the existing click-events?
I cannot "addhandler mmi.click, adressof mi.click" and
"adressof mi.onclick" also fails because it's protected.
In c# I must add the handlers manually, so I know them, but in vb
it's hidden...
<br />
For Each Mi As ToolStripItem In FileMenu.DropDownItems<br />
If TypeOf (Mi) Is ToolStripMenuItem Then<br />
Dim mmi As New ToolStripButton<br />
mmi.Text = ""<br />
mmi.Image = Mi.Image<br />
mmi.ToolTipText = Mi.Text<br />
<br />
addhandler mmi.click, "get the handler of the mi.click-event"<br />
<br />
tsProgramm.Items.Add(mmi)<br />
ElseIf TypeOf (Mi) Is ToolStripSeparator Then<br />
Dim mmi As New ToolStripSeparator<br />
tsProgramm.Items.Add(mmi)<br />
Else<br />
<br />
End If<br />
Next<br />
Thanks in advance
Chris
|
|
|
|
|
Where is this existing click handler coming from?
If you haven't created and assigned one, it doesn't yet exist.
If you have, then keep a reference to the delegate for later assignment.
If you're refering to one used by the control internally, it maybe accessible via reflection - but that would be very poor design.
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
MidwestLimey wrote: Where is this existing click handler coming from?
I wrote it, every menuitem has a eg fileopen_click(sender, e) handles fileopen.click.
MidwestLimey wrote: If you have, then keep a reference to the delegate for later assignment.
Isn't there a get-the-address-of-the-onclick-event--function in the .net-jungle?
MidwestLimey wrote: If you're refering to one used by the control internally, it maybe accessible via reflection - but that would be very poor design.
Ugly, yes...
Fastest way would be coding out every menuitem, but that's not very genious.
Thanks for your answer
Chris
|
|
|
|
|
I got a solution, but with that I have to declare all Menuitem_Click-Subs as Public and I have to set an InitFlag into them to supress invocation, because CallByName calls the event...
For Each Mi As ToolStripItem In FileMenu.DropDownItems<br />
If TypeOf (Mi) Is ToolStripMenuItem Then<br />
Dim mmi As New ToolStripButton<br />
mmi.Text = ""<br />
mmi.Image = Mi.Image<br />
mmi.ToolTipText = Mi.Text<br />
Dim pArray() As Object = {Mi, New System.EventArgs}<br />
<br />
Dim delegateMn As System.EventHandler = CType(CallByName(Me, Mi.Name & "_Click", CallType.Method), System.EventHandler)<br />
AddHandler mmi.Click, delegateMn<br />
<br />
tsProgramm.Items.Add(mmi)<br />
ElseIf TypeOf (Mi) Is ToolStripSeparator Then<br />
Dim mmi As New ToolStripSeparator<br />
tsProgramm.Items.Add(mmi)<br />
Else<br />
<br />
End If<br />
Next
|
|
|
|
|
Why not declare the delegate ahead of time and then assign to each item's event?
Dim myDelegate As EventHandler = AddressOf MenuItem_Click
Where MenuItem_Click is a generic event handler for tool strip menu items.
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
Then I have to write 15 or more new delegates? Right?
The aim was to add a toolstrip to the existing menustrip to act like a buddy.
The new toolstrips get all properties from the existing menustrips and share the same events (there are more than 1 menustrip in the mdi).
So I thought I could put some code-lines into a loop....
|
|
|
|
|
If I understand what you're trying to do (bear with me, I'm slow today!), then wouldn't it be easier to add a general event handler to the buddy strip buttons that calls PerformClick on the appropriate menu buttons? You could maintain context via either the Tag property or a dictionary.
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
That would be a very good solution. I'll try it out.
Thanks
Chris
|
|
|
|
|
Hi
Don't think this is VB.NET but... How do I loop thru each non-empty row in Excel VBA?
<br />
For Each oSheet In Worksheets<br />
For Each oRw In oSheet.Rows<br />
IsRowEmpty(oRw) ' Do I need to code IsRowEmpty?<br />
Next oRw<br />
Next oSheet
Thanks
devy
|
|
|
|
|
devvvy wrote: IsRowEmpty(oRw) ' Do I need to code IsRowEmpty?
Yes, because "empty" can have any number of meanings. Does empty mean that there are no values?, no formulas?, no formatting?, ... You have to code this to test to see if the row meets your specification of "empty".
|
|
|
|
|
Okay you are right. But then comes another technical problem...
say I selected three rows on worksheet.
Worksheets("Data").ActiveCell.Row only gives you ONE of the three selected rows.
How do I retrieves all three selected rows?
Thanks!
devy
|
|
|
|
|
Just found solution thanks anyway:
<br />
Dim rngActive As Excel.Range<br />
Set rngActive = Selection<br />
For Each oRecord In rngActive.Rows<br />
... do something ...<br />
Next oRecord<br />
devy
|
|
|
|
|
how to i save time n date in to database....i just know the code for show time n date..
datetimepicker.value=datetimepicker.now
how can i store it into database....can i use the update same as textbox and combo box..example like receipt there is date on top...when end of month i need retrieve from 1/1/08 until 31/1/08 how i can write the code
to update the latest date,and i stil can retrieve previous date...
i try below this but can't ,can some one teach me or give some idea..
"Me.TimeTableAdapter.Update(Me.timeDataSet.timeIn)"
can any one help me up..thanks in advanced....
this problem should be solved using vb.net 2005 and sql server for database
kevin
modified on Monday, March 31, 2008 10:10 AM
|
|
|
|
|
If you want to put data into an SQL database, you'll want to look at the INSERT command and it's uses. If you want to select data from an SQL database, you'll want to look at the SELECT command as well.
Whenever you insert a row into an SQL database, it will remain there unless you delete it, so running SELECT commands in order to handle data will not remove anything.
Here's a helpful link that explains a lot about SQL queries.
http://www.w3schools.com/sql/[^]
|
|
|
|
|
I'm geting an error message saying that "no value given for one or more required parameters"
e.fullPath is correct and the feild names are identical to the ones in excel apart from 'reason mobilised'. I have put it in [] because of the space. I would do a select * but there are many other feilds that don't need to be read at this stage.
Here's the code:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;" _
& "data source=" & e.FullPath & "; " & "Extended Properties=Excel 8.0;")
Dim DtSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
' Select the data from Sheet1 of the workbook.
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select INCIDENT_NO," _
& "INC_TYPE,ESTATE,TOWN,COUNTY,NAME_AND_PHONE_NO,CALLSIGN,[REASON MOBILISED]," _
& "MOBS_DT,MTI,INATT,STOP,MAV,AHS,OPERATOR_INFO from [sheet1$]", MyConnection)
DtSet = New System.Data.DataSet
MyCommand.Fill(DtSet)
MyConnection.Close()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
As always any help you can provide will be appreciated.
Colonel-yum-yum
|
|
|
|