I'm customising the Group Headers on a Telerik RadGrid by injecting a LinkButton into it during the ItemDataBound event. The button renders perfectly, but I can't get it to hit any event handlers.
Here is the code for the button creation:
Private Sub rgWorkRequestItemCosts_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgWorkRequestItemCosts.ItemDataBound
If TypeOf e.Item Is GridGroupHeaderItem Then
Dim oItem As GridGroupHeaderItem = DirectCast(e.Item, GridGroupHeaderItem)
Dim lnkAdd As New LinkButton()
lnkAdd.ID = "lnkAdd"
lnkAdd.CommandName = "CustomAddWorkRequestItemCost"
lnkAdd.CommandArgument = DirectCast(oItem.DataItem, DataRowView).Row("nWorkRequestItemID").ToString()
lnkAdd.Text = String.Format("<img style=""border:0px"" alt="""" width=""12"" src=""{0}"" /> Add new cost", ResolveUrl(String.Format("~/App_Themes/{0}/Grid/AddRecord.gif", Page.Theme)))
lnkAdd.Style("color") = "#000000"
lnkAdd.Style("text-decoration") = "none"
AddHandler lnkAdd.Click, AddressOf lnkAdd_Click
Dim tcPlaceholder As GridTableCell = DirectCast(oItem.Controls(1), GridTableCell)
Dim litText As New LiteralControl(String.Format(" {0}", tcPlaceholder.Text))
tcPlaceholder.Text = String.Empty
tcPlaceholder.Controls.Add(lnkAdd)
tcPlaceholder.Controls.Add(litText)
End If
End Sub
This code explicitly adds a handler for the LinkButton, but that handler is never hit. I've also tried events on the RadGrid (ItemCommand, ItemEvent) but none seem to get hit.
Has anyone got any suggestions of other events to try, or ways to make this work?
Thanks!
I wasn't able to find a "nice" solution to this. In the end I did the following:
Created the button in the
ItemCreated event handler, setting
its CommandArgument to a counter
which was incremented for every
group header created
Again created the button in the
ItemDataBound event, again settings
its CommandArgument to the counter
value. At this point I added a
record to a dictionary object
(stored in ViewState) linking the
counter to the actual value of the
group.
Handled the click event of the
button, extracting the group value
from the dictionary in viewstate to
complete the processing.
Ugly, but it works.
Related
I'm in the process of converting some outlook VBA macros to an Add-in. I am having difficulty with my macros that create emails based on a template. I decided to code a simple button to create and display a new email with the subject test.
Everything is working up to displaying the email which doesn't happen.
Private Sub ButtonGenEmail_Click(sender As Object, e As EventArgs) Handles ButtonGenEmail.Click
Me.Close()
Dim objApp As Outlook.Application
Dim objMail As Outlook.MailItem
objApp = Globals.ThisAddIn.Application
objMail = objApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
objMail.Subject = "test"
objMail.Save()
objMail.Display(False)
End Sub
At one point I added msgbox "Done" after objMail.Display(False) and the message never appears.
Thanks in advance
This should obviously work. I'm not so skilled in Outlook but I guess the problem here is that you run it from a form (I see the Me.Close)
Isn't then Outlook blocking to display the mail because the form is still open (I guess modal = ShowDialog())?
I think you will have to either change the form to be not modal (use Show() instead of ShowDialog()) or handle the event after the form is closed, something like
All code below written from top of my mind, so I may miss something
A method from where you initialize the form
Dim frm as new YourForm()
frm.ShowDialog()
if frm.MyState = TheyClickOnButton Then
' Run your mailItem code here
End If
in the form code
Public Enum State
Unknown = 0
TheyClickedOnButton
End Enum
Public Property MyState as State
Private Sub ButtonGenEmail_Click(sender As Object, e As EventArgs) Handles ButtonGenEmail.Click
MyState = TheyClickedOnButton
Me.Close()
End Sub
I've got a RadGrid with a GridAttachmentColumn named "FileName". I'm trying to get (FindControl) the control out of the GridDataItem in the ItemCreated event. Specifically, I want the button control (or linkButton in this case). item.FindControl("FileName") always returns Nothing.
Protected Sub AttachmentsRadGrid_ItemCreated(sender As Object, e As GridItemEventArgs)
If TypeOf e.Item Is GridDataItem Then
Dim item As GridDataItem = TryCast(e.Item, GridDataItem)
If item IsNot Nothing Then
Dim FileName = item.FindControl("FileName") 'Always Nothing
If FileName IsNot Nothing Then
'Do something with it
End If
End If
End If
End Sub
Dim button As LinkButton = TryCast(item("FileName").Controls(0), LinkButton)
OR
Dim FileName = item.FindControl("gac_FileName")
The first line of code might be Telerik's preference so I put that line first. Notice that the AttachmentColumn in read mode is basically just a linkbutton.
Notice in the 2nd example that "gac_" in item.FindControl("gac_FileName") is added to the front of the UniqueName of the column. I noticed it in Chrome DevTools when I inspected the element from the browser. I should note that "FileName" is the UniqueName of the column in case you didn't want to read through the code above.
Safer method, and Telrik's preferred method is to call the control by name rather than index...
Dim button As LinkButton = TryCast(item("FileName").Controls("gac_FileName"), LinkButton)
I have two form in my application i am calling two form together from master page.i wrote code in my master page
in top i declared like this
Dim form As New FrmDelivary
Dim frm1 As New FrmrecievedDelivaryRequest
in toolstrip menu event like this:
Dim frm1 As New FrmrecievedDelivaryRequest
frm1.Location = New Point(625, 225)
frm1.MdiParent = Me
frm1.Show()
Dim frm2 As New FrmDelivary
frm2.Location = New Point(965, 0)
frm2.MdiParent = Me
frm.show()
if i press R i want to go my cursor the particular textbox of FrmrecievedDelivaryRequest
if i press D i want to go my cursor the particular textbox of FrmDelivary
How can I do this? i trey something like this in frmMaster_KeyDown event: but same page is showing again. I have already open instance of FrmDelivary, so I don't want to show same page again. I want to just get cursor position to particular textbox of this form
If e.KeyCode = Keys.A Then
form.Show()
form.txtTicket.Focus()
Cursor.Position = form.txtTicket.Location
end if
I am working on vb.net windows application
After
frm1.Show()
place
frm1.txtTicket.Focus()
I don't think you need the Cursor.Position call
Set your frm1 and frm2 variables at the top of the code window so they are accessible from all of the Subs. In your KeyDown event, put
If e.KeyCode = Keys.A Then
frm1.Show()
frm1.txtTicket.Focus()
Cursor.Position = frm1.txtTicket.Location
end if
The problem is that you are instantiating a new copy of the form with the "AS NEW frmDelivery" statement.
I am trying to create a clone of an object instance.
Creating the new instance and copying property values is no problem but the original object instance has some event handlers assigned to its events. How can I copy event handlers to the new instance?
Thanks..
Here is a code sample...
Public Sub ButtonClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show(sender.Name + "was clicked")
End Sub
Public Sub CloneButton()
Dim newButton = New Button
newButton.Name = Button1.Name + "_Clone"
newButton.Text = Button1.Text
newButton.Width = Button1.Width
newButton.Height = Button1.Height
'Some code here to copy Button1's event handler ButtonClick,
'so when the new button is clicked "Button1_Clone was clicked" is displayed.
End Sub
This is freakin' old, I know, but I can't believe this guy didn't get an answer, it's been answered on SO before, right here.
Just one thing; in the example code given, miHandler will be Nothing if there is no event handler attached to the sourceObject, you should test for that.
i'm using the mshtml.tlb for loading/parsing html and i'd like extend it for clicking elements by code. the problem is trapping the loading-process after eg. a button was clicked.
in my specific case i'd like to perform a user-login.
here's my code:
Dim WithEvents m_doc As HTMLDocument
' load page
Set m_docNU = New HTMLDocument
Set m_doc = m_docNU.createDocumentFromUrl(m_url, vbNullString)
Do While m_doc.readyState = "loading" Or m_doc.readyState = "interactive"
DoEvents
Loop
set txtUsername = m_doc.getElementById("username")
set txtPasswort = m_doc.getElementById("passwort")
set myButton = m_doc.getElementById("submit")
myButton.click
now here's the big question mark: how to continue vb6- like "wait until page is loaded"?
i've tried as above using a do while-loop and checking the readyState, but for some reason the readyState doesn't change after clicking the button ..
any ideas?
thanks
ps: is there a more elegant way instead of the do while-loop? eg. using a progressbar?
use vb.net
wBrowser is a webbroser object
While wBrowser.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
End While