|
can i add items of type Object rather than strings to a ListView control?
No
Only Strings or ListViewItems
|
|
|
|
|
I am trying to recognize text from a recorded wav file.
I use MS Speech SDK 5.1 and VB.Net.
Here's my project . It compiles OK but i get nothing as a recognized text.PLEASE HELP!
I have an initialise function ,an openstream function to open the file i want and the other important function is the RecoContext_Recognition which is called when a recognition event is created.
What am i doing wrong?!?!?
Imports SpeechLib
Public Class STT_Controller
Private Recocontext As SpInProcRecoContext = New SpeechLib.SpInProcRecoContextClass 'Recognized context
Private grammar As ISpeechRecoGrammar 'Recognize Grammar
Private inputfile As New SpFileStream 'Imported file stream
Private reco As SpInprocRecognizer = New SpInprocRecognizerClass
Public ErrorNumber As Integer
Private StreamOpened As Boolean = False
Private STTResult As String = ""
Event Recognition_EndOfStream()
Event Recognition_Start()
Public ReadOnly Property ResultText()
Get
Return STTResult
End Get
End Property
Public Sub Initialise() 'Ekkinisi tis engine
On Error Resume Next
Dim reco As SpInprocRecognizer = New SpInprocRecognizerClass
If Not (Err.Number = 0) Then ErrorNumber = 704
'Event Handlers
AddHandler Recocontext.EndStream, AddressOf RecoContext_EndStream
AddHandler Recocontext.Recognition, AddressOf RecoContext_Recognition
Recocontext = reco.CreateRecoContext
If Not (Err.Number = 0) Then ErrorNumber = 701
grammar = Recocontext.CreateGrammar
If Not (Err.Number = 0) Then ErrorNumber = 702
grammar.DictationLoad()
If Not (Err.Number = 0) Then ErrorNumber = 703
End Sub
Public Sub Activate()
On Error Resume Next
grammar.DictationSetState(SpeechRuleState.SGDSActive)
If Not (Err.Number = 0) Then ErrorNumber = 801
End Sub
Public Sub Deactivate(Optional ByVal UnloadGrammar As Boolean = False)
On Error Resume Next
grammar.DictationSetState(SpeechRuleState.SGDSInactive)
If UnloadGrammar = True Then grammar.DictationUnload()
End Sub
Private Sub RecoContext_EndStream(ByVal StreamNumber As Integer, ByVal StreamPosition As Object, ByVal StreamReleased As Boolean)
RaiseEvent Recognition_EndOfStream()
Deactivate()
End Sub
Private Sub RecoContext_Recognition(ByVal StreamNumber As Integer, ByVal StreamPosition As Object, ByVal RecognitionType As SpeechLib.SpeechRecognitionType, ByVal result As SpeechLib.ISpeechRecoResult)
RaiseEvent Recognition_EndOfStream()
STTResult = result.PhraseInfo.GetText
End Sub
Public Sub OpenStream(ByVal Fname As String, ByVal mode As SpeechLib.SpeechStreamFileMode, Optional ByVal DoEv As Boolean = False)
On Error GoTo openstreamerr
If StreamOpened = True Then inputfile.Close()
inputfile.Open(Fname, mode, DoEv)
StreamOpened = True
reco.AudioInputStream = inputfile
Exit Sub
openstreamerr:
ErrorNumber = 601
End Sub
Public Sub CloseStream()
On Error GoTo CloseStreamerr
inputfile.Close()
StreamOpened = False
Exit Sub
CloseStreamerr:
ErrorNumber = 602
End Sub
End Class
May it be your fate to live in interesting times
|
|
|
|
|
Hi.
I am coding a progam where I want the Context menu to CLOSE if it is already open and you press right mouse button again.
This is something that seems VERY hard to acomplish.
The code below manages to do it 2 times, but when you right click with an open context menu the 3 time, then you get a context menu even tough I do NOT want it:
Private Sub ListView1_GetMenu(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseUp
ListView1.ContextMenu = Nothing
If contextIsActive = True Then SendKeys.Send("{ESC}")
' Checking the Mouse right Button
If e.Button = MouseButtons.Right Then
Try
currentItem = sender.GetItemAt(e.X, e.Y)
If Not currentItem Is Nothing And contextIsActive = False And ListView1.ContextMenu Is Nothing Then
Me.ContextMenu1.MenuItems.Add(Me.MenuItem1)
ListView1.ContextMenu = Me.ContextMenu1
ListView1.ContextMenu.Show(sender, New Point(e.X, e.Y))
contextIsActive = True
ElseIf contextIsActive = False And ListView1.ContextMenu Is Nothing Then
MenuItem1.Text = ""
Me.ContextMenu1.MenuItems.Remove(Me.MenuItem1)
ListView1.ContextMenu = Me.ContextMenu1
ListView1.ContextMenu.Show(sender, New Point(e.X, e.Y))
contextIsActive = True
Else
SendKeys.Send("{ESC}")
Me.ContextMenu1.MenuItems.Remove(Me.MenuItem1)
Me.ContextMenu1.MenuItems.Remove(Me.MenuItem2)
ListView1.ContextMenu = Nothing
contextIsActive = False
End If
Catch
Me.ListView1_GetMenu(sender, e)
End Try
End If
End Sub
Private Sub contextMenu1_Popup(ByVal sender As Object, ByVal e As System.EventArgs) Handles ContextMenu1.Popup
If contextIsActive = False And ListView1.ContextMenu Is Nothing Then SendKeys.Send("{ESC}")
End Sub
As you can see from the code here I have LOTS of different ways for the damn context menu to close. None of which seems to work. I really REALLY need to get this to work. It HAS to work.
PLEASE help!
Anders Liden
Gothenburg Sweden
|
|
|
|
|
Hello Anders
I was wondering if you ever got an answer to your above question. I am having the same problem. If so could you post your resolution.
Thanks
"The things that will destroy us are: politics without principle; pleasure without conscience; wealth without work; knowledge without character; business without morality; science without humanity; and worship without sacrifice."
-Mahatma Gandhi (1869-1948)
|
|
|
|
|
Hi everybody. I got a simple question about loading a DLL in a VB 6 (or .NET) Application. This doesn't seem to work right. I am trying to find some way of loading a DLL without specifying the full path and without the DLL being located in the \Windows folder. For example when you have the DLL in the same folder with the Application. I tried only specifying the DLL like:
Public Declare Function SomeFunction "Somedll.dll" () as Long.
This doesn't work. Probably it looks for it in the Windows folder. As I read in the MSDN documentation it should look for it first in the Application folder, but this doesn't happen as it seems.... To complicate thing worst, I can't specify the path for the Application right there because I get a compilation error:
Public Declare Function SomeFunction App.Path & "\Somedll.dll" () as Long. '-----> This doesn't work.
I saw this in a book:
Public Declare Function SomeFunction ".\SomeFolder\Somedll.dll" () as Long.
So I tried:
Public Declare Function SomeFunction ".\Somedll.dll" () as Long.
This ain't workin' either. Anybody got a clue? : )
Thanks! : )
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
You'll never get it to work this way because it's a compile-time only declaration. It can't be modified at run-time.
I wish I could tell you more but I just got called out of the office... Sorry!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi Dave : ). There's no rush for me right now.... I was just wondering if I could link directly to a DLL in my Application's folder, rather than storing it in the Windows folder. It seems that I will be forced to save it in the Windows folder... but even so, how can I know where will the future users of my Application have their Windows folder? I mean, there's no guarantee that VB will find the DLL if I put it there right??
Anyway... what do you think about this piece of code? I found it in a book about Hooks and Subclassing in Visual Basic...
Public Declare Function SomeFunction ".\SomeFolder\Somedll.dll" () as Long.
What does that path mean? That the "somedll.dll" file is located in the SomeFolder subfolder of Windows or of the Application?
Thank you.
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
Hello everybody. I'm trying to make the contents of a textbox, if they don't fit in a page to wrap and use the line underneath etc etc.
So far i can clip the string in the given rectangle i have indicate with the setclip command. Other than that i can't make it work. Here is a part of the code:
'Create string to draw.
Dim drawString As String = txtComment.Text
Dim drawString1 As String = imageToLoad
Dim drawFont As New Font("Arial", 0.4, FontStyle.Regular, GraphicsUnit.Millimeter)
Dim drawFont1 As New Font("Arial", 0.6, FontStyle.Regular, GraphicsUnit.Millimeter)
Dim drawBrush As New SolidBrush(Color.Black)
' print filename
Dim drawPoint As New PointF(0.0F, -27.0F)
'print comments
Dim drawPoint1 As New PointF(0.0F, 90.0F)
If chkComment.Checked = True Then
e.Graphics.SetClip(New Rectangle(0, 0, 100, 100))
e.Graphics.DrawString(drawString, drawFont1, drawBrush, drawPoint1)
End If
e.Graphics.DrawString(drawString1, drawFont, drawBrush, drawPoint)
' There are no more pages.
e.HasMorePages = False
The textbox in question is the txtComment.Text. Any help please?
Thank you
Still trying to find the way
|
|
|
|
|
If you use the DrawString variant that takes a Rectangle, it will wrap the string for you.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Thank you Christian. I used
Dim LayoutRen As RectangleF = New RectangleF(0, 90, 100, 300)
e.Graphics.DrawString(drawString, drawFont1, drawBrush, LayoutRen)
and it work like a charm. Thank again!
Still trying to find the way
|
|
|
|
|
Is there a easy way of saving the state of the TreeView. When you add or delete a node in the TreeView, It collapses the nodes which I don't want.
Thanks
|
|
|
|
|
Hi all,
I've a select request, with the resulset i create a dbf file, but i've a problem with the datetime data, because i need to specify the date format i nedd (dmy) in the insert request. I can't use at the begining of the program the instruction "set date to dmy", becase the class that i use to execute q query, doesn't support the instruction. So, any of you know how to specify the date format??
Thanks
|
|
|
|
|
I'm binding the data to datagrid in vb.net, and the first column is the entity_id, I don't want it to show in the datagrid, but I need to pass the entity_id to another window when the current row is selected. The entity_id is showing in my first column in my datagrid, how can I get the entity_id without showing the entity_id?
Thanks!
Lisa
|
|
|
|
|
Hi,
create a tablestyle for your datagrid and set it's mappingname appropriately. then create a columnstyle for each field you want to display in the datagrid.
on the backend you can still access everything that you have in the datagrid, but only show what makes sense to the end user.
-jim
|
|
|
|
|
thanks, Jim..
Actually, I tried to use this code
DS.Tables(0).Columns("entity_id").ColumnMapping = MappingType.Hidden
but the problem is when I click the row and need to pass the entity_id column value to other form. then it gave me error "Specified argument was out of the range of valid values. Parameter name: columnIndex."
this is my function to get the value from the datagrid.
Public Function GetSelectedRows(ByVal dg As DataGrid) As System.Collections.ArrayList
Dim al As New ArrayList
Dim cm As CurrencyManager = Me.BindingContext(dg.DataSource, dg.DataMember)
Dim dv As DataView = CType(cm.List, DataView)
Dim idCol As Integer
idCol = 5
Dim i As Integer
For i = 0 To dv.Count - 1
If dg.IsSelected(i) Then
al.Add(dg.Item(i, idCol))
End If
Next
Return al
End Function
and the idCol = 5 is the column of entity_id.
Do you have any idea for this?
Thanks!
Lisa
|
|
|
|
|
no problem lisa,
is there a particular reason why you're trying to return an arraylist? why not just return the dataview with the selected rows?
if i had to guewss, i would say that the exception is being thrown when you're trying to add to the arraylist. most likely because your datagrid doesn't have a column at index 5.
~jim
|
|
|
|
|
thanks Jim..
I fixed the problem, I set the column width to 0 in dataGridTextBoxColumn..
Lisa
|
|
|
|
|
U can Use as follows
Dim dv As DataView = New DataView(Datatable)
dv.Table.Columns(0).ColumnMapping =MappingType.Hidden ' whats the Column U wanna Hide
dv.Table.Columns(3).ColumnMapping = MappingType.Hidden
me.Datagrid.Datasource = dv
|
|
|
|
|
this will hide a whole column!
DataGrid1.Tables(0).Columns("columnName").ColumnMapping = MappingType.Hidden
the column still exists in your datasource to pass
done
|
|
|
|
|
I am developing an applicationf for health card validation, I need to access serial card reader through COM Port, can anyone help how I can do that or what methodology can be implemented?
Many Thanks (Advance)
|
|
|
|
|
|
Hi all
I have been lookin more then 3 days for a solution for my problem...
Allthough i did progress in finding out what causes the problems, I dont have any clue what the solution might be...
I really hope someone here can help me out
THX AHEAD
the problem is the following:
I have made a web user control containing a DataGrid for editing a MS SQL table. It uses the DataGrid's OnSortCommand, OnEditCommand, OnUpdateCommand, OnCancelCommand, and it all works very nicely
BUT, when i try to integrate this web user control in my big project (a webportal) it stopped working and started acting really strange
after looots of searching and debugging this is what i found out:
When i integrate it in the portal, i let my web user control inherit ControlBase.vb instead of System.Web.UI.UserControl... ControlBase.vb itself inherits System.Web.UI.UserControl, so that should normally work
I got this ControlBase.vb technique out of an article on www.smartisans.com about "Creating a Visual Web Page Template" which u can find here: http://www.smartisans.com/articles/vb_templates.aspx
After looking futher i noticed that it is the Page_PreRender function in ControlBase.vb that cause my problems... when i comment this function out, everything works perfect again...
while debugging i noticed the folowing when the Page_PreRender function is included:
When loading the page the first time, it still works like it should... Page_Load in my web user control gets called, and since IsPostBack is false, a bindgrid() is done...
but when clicking one of the links in my datagrid, it goes wrong... The Page_Load function still gets called, but since IsPostBack is true this time, nothing is done... After this, NORMALLY, the event of link i clicked should be called (fe: the OnEditCommand event), but it aint called at all... so nothing happens, and my page remains empty...
After lots of trying i also noticed some strange things:
When doing a BindGrid() in Page_Load (even when IsPostBack is true), the events do get called, but things still get f***ed up, since no bindgrid() is needed then, the dataset gets filled twice, and even when including a dataset.clear() things still dont work as expected when sorting if a collumn is in editmode
Also i noticed the Page_PreRender function gets called twice every time
I hope someone has idea why all these strange things are happening to me, cause i dont...
EVERYTHING works PERFECT without the Page_PreRender, and i just cant get it working with it... (and i need the Page_PreRender for the nice Page Template technique i guess?)
somehow, somewhere the events just get lost.....
below u can find the structure of my solution WITH the page template (the one that doesnt work, just change "inherits ControlBase" to "inherits System.Web.UI.UserControl" to see it working, ull also need a working iis and an sql server with 1 table)
solution structure
solution: afdedit<br />
project (asp.net web application): afdedit<br />
webform: default.aspx<br />
web user control: afdedit.ascx<br />
project (class library): test<br />
klasse: ControlBase.vb
and below all the code:
default.aspx
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="default.aspx.vb" Inherits="afdedit.WebForm1"%><br />
<%@ Register TagPrefix="VAB" TagName="afdedit" Src="afdedit.ascx" %><br />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><br />
<HTML><br />
<HEAD><br />
<title>WebForm1</title><br />
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1"><br />
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1"><br />
<meta name="vs_defaultClientScript" content="JavaScript"><br />
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"><br />
</HEAD><br />
<body MS_POSITIONING="GridLayout"><br />
<form id="Form1" method="post" runat="server"><br />
<VAB:afdedit runat="server" ID="afdedit" NAME="afdedit"></VAB:afdedit><br />
</form><br />
</body><br />
</HTML>
default.aspx.vb
Imports test<br />
<br />
Public Class WebForm1<br />
Inherits System.Web.UI.Page<br />
<br />
#Region " Web Form Designer Generated Code "<br />
<br />
'This call is required by the Web Form Designer.<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
<br />
End Sub<br />
<br />
'NOTE: The following placeholder declaration is required by the Web Form Designer.<br />
'Do not delete or move it.<br />
Private designerPlaceholderDeclaration As System.Object<br />
<br />
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init<br />
'CODEGEN: This method call is required by the Web Form Designer<br />
'Do not modify it using the code editor.<br />
InitializeComponent()<br />
End Sub<br />
<br />
#End Region<br />
<br />
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
'Put user code to initialize the page here<br />
End Sub<br />
<br />
End Class
afdedit.ascx
<%@ Control Language="vb" AutoEventWireup="false" Codebehind="afdedit.ascx.vb" Inherits="afdedit.afdedit" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %><br />
<DIV id="divAfdeling" align="center" runat="server"><br />
<asp:DataGrid id="DG" DataKeyField="afdelingid" AutoGenerateColumns="False" runat="server" AllowSorting="True"<br />
OnSortCommand="DG_sort" OnUpdateCommand="DG_Update" OnCancelCommand="DG_Cancel" OnEditCommand="DG_Edit"<br />
GridLines="Vertical" AlternatingItemStyle-BorderColor="#000000" AlternatingItemStyle-BackColor="LightGrey"<br />
ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" CellPadding="7"><br />
<AlternatingItemStyle HorizontalAlign="Center" BorderColor="Black" VerticalAlign="Middle" BackColor="White"></AlternatingItemStyle><br />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" BackColor="#CAC7A8"></ItemStyle><br />
<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="Gray"></HeaderStyle><br />
<Columns><br />
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn><br />
<asp:BoundColumn Visible="False" DataField="afdelingid" SortExpression="afdelingid" ReadOnly="True"<br />
HeaderText="Afdeling ID"></asp:BoundColumn><br />
<asp:BoundColumn DataField="naam" SortExpression="naam" ReadOnly="True" HeaderText="Naam"></asp:BoundColumn><br />
<asp:BoundColumn DataField="omschrijving" SortExpression="omschrijving" HeaderText="Omschrijving"></asp:BoundColumn><br />
<asp:BoundColumn DataField="url" SortExpression="url" HeaderText="Url"></asp:BoundColumn><br />
</Columns><br />
<PagerStyle VerticalAlign="Middle" HorizontalAlign="Center"></PagerStyle><br />
</asp:DataGrid><br />
</DIV>
afdedit.ascx.vb
Public Class afdedit<br />
Inherits ControlBase<br />
<br />
#Region " Web Form Designer Generated Code "<br />
<br />
'This call is required by the Web Form Designer.<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.Conn = New System.Data.SqlClient.SqlConnection<br />
Me.DA = New System.Data.SqlClient.SqlDataAdapter<br />
Me.SelComm = New System.Data.SqlClient.SqlCommand<br />
Me.UpdComm = New System.Data.SqlClient.SqlCommand<br />
Me.DS = New System.Data.DataSet<br />
Me.DV = New System.Data.DataView<br />
Me.DT = New System.Data.DataTable<br />
CType(Me.DS, System.ComponentModel.ISupportInitialize).BeginInit()<br />
CType(Me.DV, System.ComponentModel.ISupportInitialize).BeginInit()<br />
CType(Me.DT, System.ComponentModel.ISupportInitialize).BeginInit()<br />
'<br />
'Conn<br />
'<br />
Me.Conn.ConnectionString = "server=SHAREPOINT;Database=Intranet;uid=sa;pwd=VAB7vtb5$"<br />
'<br />
'DA<br />
'<br />
Me.DA.SelectCommand = Me.SelComm<br />
Me.DA.UpdateCommand = Me.UpdComm<br />
'<br />
'SelComm<br />
'<br />
Me.SelComm.CommandText = "SELECT afdelingid, naam, omschrijving, url FROM Afdelingen"<br />
Me.SelComm.Connection = Me.Conn<br />
'<br />
'UpdComm<br />
'<br />
Me.UpdComm.CommandText = "UPDATE Afdelingen SET naam = @naam, omschrijving = @omschrijving, url = @url WHER" & _<br />
"E (afdelingid = @afdelingid); SELECT naam, omschrijving, url, afdelingid FROM Af" & _<br />
"delingen WHERE (afdelingid = @afdelingid)"<br />
Me.UpdComm.Connection = Me.Conn<br />
Me.UpdComm.Parameters.Add(New System.Data.SqlClient.SqlParameter("@afdelingid", System.Data.SqlDbType.Int, 4, "afdelingid"))<br />
Me.UpdComm.Parameters.Add(New System.Data.SqlClient.SqlParameter("@naam", System.Data.SqlDbType.VarChar, 100, "naam"))<br />
Me.UpdComm.Parameters.Add(New System.Data.SqlClient.SqlParameter("@omschrijving", System.Data.SqlDbType.VarChar, 100, "omschrijving"))<br />
Me.UpdComm.Parameters.Add(New System.Data.SqlClient.SqlParameter("@url", System.Data.SqlDbType.VarChar, 100, "url"))<br />
'<br />
'DS<br />
'<br />
Me.DS.DataSetName = "DataS"<br />
Me.DS.Locale = New System.Globalization.CultureInfo("nl-BE")<br />
'<br />
'DT<br />
'<br />
Me.DT.TableName = "afdelingen"<br />
CType(Me.DS, System.ComponentModel.ISupportInitialize).EndInit()<br />
CType(Me.DV, System.ComponentModel.ISupportInitialize).EndInit()<br />
CType(Me.DT, System.ComponentModel.ISupportInitialize).EndInit()<br />
<br />
End Sub<br />
Protected WithEvents DG As System.Web.UI.WebControls.DataGrid<br />
Protected WithEvents DA As System.Data.SqlClient.SqlDataAdapter<br />
Protected WithEvents DS As System.Data.DataSet<br />
Protected WithEvents DV As System.Data.DataView<br />
Protected WithEvents DT As System.Data.DataTable<br />
Protected WithEvents Conn As System.Data.SqlClient.SqlConnection<br />
Protected WithEvents SelComm As System.Data.SqlClient.SqlCommand<br />
Protected WithEvents UpdComm As System.Data.SqlClient.SqlCommand<br />
Protected WithEvents divAfdeling As System.Web.UI.HtmlControls.HtmlGenericControl<br />
<br />
'NOTE: The following placeholder declaration is required by the Web Form Designer.<br />
'Do not delete or move it.<br />
Private designerPlaceholderDeclaration As System.Object<br />
<br />
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init<br />
'CODEGEN: This method call is required by the Web Form Designer<br />
'Do not modify it using the code editor.<br />
InitializeComponent()<br />
End Sub<br />
<br />
#End Region<br />
<br />
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
'Put user code to initialize the page here<br />
If Not IsPostBack Then<br />
Session("EditID") = -1<br />
Session("Direction") = " ASC"<br />
Session("SortField") = "naam"<br />
BindGrid()<br />
End If<br />
End Sub<br />
<br />
' Sorteren op een bepaalde kolom door kolomhoofding aan te klikken<br />
Public Sub DG_sort(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles DG.SortCommand<br />
' Als een rij in "edit-modus" is<br />
If DG.EditItemIndex <> -1 Then<br />
FindEditPosKey()<br />
End If<br />
' Als er geklikt is op de kolom waarop al gesorteerd is<br />
If CType(Session("SortField"), String) = e.SortExpression Then<br />
' Indien oplopend wordt gesorteerd, aflopend sorteren, en analoog andersom<br />
If CType(Session("Direction"), String) = " ASC" Then<br />
Session("Direction") = " DESC"<br />
Else<br />
Session("Direction") = " ASC"<br />
End If<br />
Else<br />
Session("Direction") = " ASC"<br />
End If<br />
' Kolom onthouden waarop gesorteerd wordt<br />
Session("SortField") = e.SortExpression<br />
BindGrid()<br />
End Sub<br />
<br />
' Edit-layout voor een bepaalde rij activeren<br />
Public Sub DG_Edit(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DG.EditCommand<br />
DG.EditItemIndex = e.Item.ItemIndex<br />
BindGrid()<br />
End Sub<br />
<br />
' Updaten van een gewijzigde rij<br />
Public Sub DG_update(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DG.UpdateCommand<br />
' definieren van de textboxes gecreeerd door de edit-layout te openen voor een rij<br />
Dim tb_omschrijving As TextBox = CType(e.Item.Cells(3).Controls(0), TextBox)<br />
Dim tb_url As TextBox = CType(e.Item.Cells(4).Controls(0), TextBox)<br />
' vastleggen van alle cellen van de te wijzigen rij<br />
Dim afdelingid As Integer = CInt(e.Item.Cells(1).Text)<br />
Dim naam As String = e.Item.Cells(2).Text<br />
Dim omschrijving As String = tb_omschrijving.Text<br />
Dim url As String = tb_url.Text<br />
If omschrijving.Length = 0 Or omschrijving.Length > 30 Or Not Geen_SQL_Injection(omschrijving) Then<br />
' invoercontrole van omschrijving<br />
Fout("Ongeldige omschrijving... De omschrijving moet minstens 1 teken en mag maximum 29 tekens zijn... " & _<br />
"Volgende tekens zijn niet toegelaten: ', "", *, <, >")<br />
ElseIf url.Length < 8 Then<br />
' invoercontrole van url<br />
Fout("Ongeldige URL... Een URL begint met 'http:
ElseIf url.Substring(0, 7) <> "http://" Or Not Geen_SQL_Injection(url) Then<br />
' verdere invoercontrole van url<br />
Fout("Ongeldige URL... Een URL begint met 'http:
Else<br />
' als alle invoercontrole doorlopen is<br />
' sql parameters laden<br />
Me.UpdComm.Parameters("@afdelingid").Value() = afdelingid<br />
Me.UpdComm.Parameters("@naam").Value() = naam<br />
Me.UpdComm.Parameters("@omschrijving").Value() = omschrijving<br />
Me.UpdComm.Parameters("@url").Value() = url<br />
' connectie openen, rij updaten, connectie sluiten, edit-layout ongedaan maken en datagrid herladen<br />
Conn.Open()<br />
Me.UpdComm.ExecuteNonQuery()<br />
Conn.Close()<br />
DG.EditItemIndex = -1<br />
BindGrid()<br />
End If<br />
End Sub<br />
<br />
' Invoercontrole tegen SQL Injection<br />
Private Function Geen_SQL_Injection(ByVal code As String) As Boolean<br />
Return code.IndexOf("'") = -1 And code.IndexOf("*") = -1 And _<br />
code.IndexOf("<") = -1 And code.IndexOf(">") = -1 And code.IndexOf("""") = -1<br />
End Function<br />
<br />
' Foutmelding bij het wijzigen van een veld<br />
Private Sub Fout(ByVal bericht As String)<br />
DG.EditItemIndex = -1 ' edit-layout ongedaan maken<br />
BindGrid() ' datagrid herladen<br />
Response.Write(bericht) ' foutmelding tonen<br />
End Sub<br />
<br />
' Edit-layout ongedaan maken en datagrid herladen<br />
Public Sub DG_Cancel(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DG.CancelCommand<br />
DG.EditItemIndex = -1<br />
BindGrid()<br />
End Sub<br />
<br />
' Zoekt de primary key van het veld in "edit-modus"<br />
Private Sub FindEditPosKey()<br />
' Dataview vullen met gesorteerd op oude sorteer kolom<br />
DA.Fill(DS, "afdelingen")<br />
DV = DS.Tables("afdelingen").DefaultView<br />
DV.Sort = CType(Session("SortField"), String) & CType(Session("Direction"), String)<br />
' Primary key van rij in "edit-modus" opslaan<br />
Session("EditID") = DV.Item(DG.EditItemIndex).Row.Item(0)<br />
' DataSet leegmaken<br />
DS.Clear()<br />
End Sub<br />
<br />
' Herlaad de grid gesorteerd op SortField<br />
Private Sub BindGrid()<br />
' Dataview vullen en datagrid herladen<br />
DA.Fill(DS, "afdelingen")<br />
DV = DS.Tables("afdelingen").DefaultView<br />
DV.Sort = CType(Session("SortField"), String) & CType(Session("Direction"), String)<br />
DG.DataSource = DV<br />
DG.DataBind()<br />
' Indien een rij in "edit-modus" stond<br />
If CInt(Session("EditID")) <> -1 Then<br />
Dim RijIndex As Integer = 0<br />
' zolang er rijen zijn en zolang de primary key niet gevonden is, RijIndex verhogen<br />
While RijIndex < DG.Items.Count And CInt(DG.DataKeys(RijIndex)) <> CInt(Session("EditID"))<br />
RijIndex += 1<br />
End While<br />
' zoeken naar rij in "edit-modus" uitschakelen<br />
Session("EditID") = -1<br />
' de juiste rij in de "edit-modus" zetten<br />
DG.EditItemIndex = RijIndex<br />
' DataSet leegmaken<br />
DS.Clear()<br />
BindGrid()<br />
End If<br />
End Sub<br />
<br />
End Class
ControlBase.vb
Imports System<br />
Imports System.Web<br />
Imports System.Web.UI<br />
Imports System.Configuration<br />
Imports System.Data.SqlClient<br />
Imports System.Resources<br />
<br />
' ************************************************************<br />
' Controle klasse voor standaard layout van een pagina<br />
' ************************************************************<br />
<br />
Public Class ControlBase<br />
Inherits System.Web.UI.UserControl<br />
Private sHeader As String<br />
<br />
Public Property Header() As String<br />
Get<br />
Return sHeader<br />
End Get<br />
Set(ByVal Value As String)<br />
' Opmaak van de header<br />
sHeader = "<.h1>" & Value & "</.h1>"<br />
End Set<br />
End Property<br />
<br />
Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender<br />
' Toevoegen van een header <br />
Me.Controls.AddAt(0, New LiteralControl(Header()))<br />
End Sub<br />
<br />
'Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)<br />
' writer.WriteLine(Header())<br />
'End Sub<br />
<br />
End Class
|
|
|
|
|
i just found this on http://www.jroller.com/page/CoBraLorD/20040812#asp_net_datagrid_events_not
ASP.NET: DataGrid events not firing without ViewState ? ( 12 aug 2004, 10:53:02 CEST )<br />
Many of us ASP.NET developers must have had this problems, DataGrid events don't fire unless you enable viewstate on the datagrid, or you rebind it on every page load (so before the eventhandler gets called). Viewstate can be a nasty thing, especially in combination with a datagrid, and since I have to target low bandwith users, I tend to drop the viewstate for my datagrids. <br />
<br />
So I must rebind the datagrid on every page load if I want to be able to catch events originating from a child control inside it. Reason for this: the controls inside a datagrid (like for example a LinkButton for every item) are only created when the data is actually bound. Let's say an ItemCommand is launched by clicking on a linkbutton in the datagrid. The page gets loaded on the other side, but its a postback and you don't databind() the grid (and viewstate is disabled). After the basic page load, the UI Page class will look for the control that raised the event, but, it won't find it since it has not yet been created. In the end the eventhandler will not get called. <br />
<br />
Now, if you don't want viewstate, a databind on every page load works fine in most cases. However, what if you have a very expensive query to fill up your datagrid. Or say you have a datagrid on a page, along with another set of buttons. Each of the buttons raises an event, but those events will navigate away from the page, so you definitely won't see that datagrid anymore. It's pretty damn annoying to end up loading the whole datagrid data ANYWAY, just to be able to handle that button click that immediately moves away from the current page. That's seriously one wasted query. <br />
<br />
However, there is a solution, and in fact, it's pretty easy !<br />
What you want to is basically intercept on what control an event is being called, and then decide if you should bind data to be able to actually 'catch' the event. For example: we know if an event is being called on any child control of our datagrid, we must rebind the datagrid first. If an event is being called on one of our buttons, we know we will simply redirect and we don't need to bind the datagrid for that. <br />
<br />
The answer is __EVENTTARGET. The event target is a request parameter that gets set automatically on the postback of a form. It is either set in the querystring or form collection (depending on your form method). In case of a control *inside* another control being called, the event target will show you something of the form 'XXXX:_ctl1:_ctl2...' where XXXX is the ID of a control you created manually. So, if you were to have a datagrid called dgUserList, a linkbutton event could very well be of the form dgUserList:_ctl2:_ctl0. <br />
<br />
What you could do then is in the Page_Load method, get the __EVENTTARGET value (you can easily use Request.Params instead of checking for both Form and QueryString separately) and check if the string dgUserList is somewhere in there (or if it starts with it). If so, we can be sure we need to rebind the datalist, else we're sure we don't have to, just to be able to handle the event. This allows you a more fine-grained control over when to rebind data to controls, and it can gain you some performance if your application would demand it. <br />
<br />
You could go quite far with this, actually linking up databinding with a set of events, before the actual eventhandlers are being executed.
it seems to go about the same problem, only i dont understand the solution and i still didnt get it working
also my viewstate is allready true, so i dont really understand why im having this problem?
|
|
|
|
|
hello,
i want to know how can i get the text which is under mouse cursor,even if the cusror is out of my application's window. I am using VB.Net
|
|
|
|
|
Sound simple enough, right? But, you've got ALOT of research to do. What you want to do is going to be nearly impossible beause of how Windows works and the number of different controls that can have text. You can probably go as far as getting the WHOLE text from a control, but you will find getting just the word under the cursor requires calling methods on controls that you can't call directly. This project will require an expert level of knowledge of Windows internals, MFC, ATL, control classes from a C++ view, (not VB.NET!), and COM Interop.
Have fun! Oh! You'll have to look very long and hard to find examples of any of this code on the web, if it exists at all.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|