|
Hi, I am writing this in hopes that someone out there can help me with the creation or a work around for how to write custom events in vb.net.
eg.
public event CustomEvent as Something
{
add
{
this.Pevent+=value ;
}
remove
{
this.Pevent-=value;
}
}
All that I can do in vb.net seems to be
Private event Pevent as SomethingHandler
Public event CustomEvent as SomethingHandler
I need this event to occur when the user clicks in a cell of a datagrid. It will addhander through a private function. But, I don't know if this is possible or how to do this in vb.net. Help please. Thank you.
eatwork
|
|
|
|
|
Something like this (obtained with Instant VB after adding a delegate declaration):
Public Delegate Sub Something(ByVal sender As Object, ByVal e As System.EventArgs)
Public Custom Event CustomEvent As Something
AddHandler(ByVal value As Something)
AddHandler Me.Pevent, value
End AddHandler
RemoveHandler(ByVal value As Something)
RemoveHandler Me.Pevent, value
End RemoveHandler
RaiseEvent(ByVal sender As Object, ByVal e As System.EventArgs)
End RaiseEvent
End Event
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter and VB to C++ converter
Instant J#: VB to J# converter
Clear VB: Cleans up VB.NET code
Clear C#: Cleans up C# code
|
|
|
|
|
Hi David,
Thank you for your response and solution. I will give that a try, but it looks like it should work. Thank you.
eatwork
|
|
|
|
|
There is an even better way to do this now in Visual Basic for .NET 4.0:
Here is a perfect example of using Visual Basic's Custom Event which also includes new multi-line Lamda's which were available in C# and not VB. I switched to C# since it always seemed ahead of VB and have been really happy yet with .NET, you can always mix and match so can still use things like VB's inline XML for parts of your solution. What is disturbing to me though is that the more I learn about non-Microsoft languages, the more I find out that a lot of this stuff has been done before. Now I just try to learn everything which is impossible and has caused me to go Col. Walter E. Kurtz... The Horror, The Horror...
Here is the link to Bill Wagner's amazing code(It's topic is Tuples feature yet there is a rework of his October 2009 article code using Custom Event, Tuples, and Multi-Line Lamda's that is a perfect example of what you can do and shows what you wanted as well):
|
|
|
|
|
|
hello
i am facing a very small problem related to combo box actually i want to disable text input in combo box like when i run my form u can select an item and u can also modify it although u cant save the changes but why it happens i want to disable not the combobox but only the text writting cursor so u cant write any thing in it so plz help me as soon as possible thanks
|
|
|
|
|
Set the combo box's "DropDownStyle" to "DropDownList"
|
|
|
|
|
ya it works but it don'nt show the display text like "select country" how i can do it
|
|
|
|
|
Set your Text Property to "Select Country"
|
|
|
|
|
Hi,
Directly you wont be able to assign that. What you need to do is when you are binding it at that itself you add that to your datasource.
Best Regards,
Apurva Kaushal
|
|
|
|
|
Hello,
I'm working with the datagridview and I want format the columns with values from a database
code :
For Each DC In DGV.Columns
Dim cell As DataGridViewCell = New DataGridViewTextBoxCell()
'Dim cell As DataGridViewCell = New DataGridViewButtonCell
Me.Text = DataList.TableColumns.Rows.Count
DC.Tag = 0
DC.Tag = DataList.TableColumns.Rows(DC.Index).Item("PrgFormule")
If DC.Tag = 0 Then
cell.Style.BackColor = Color.LightGray
DC.ReadOnly = True
Else
cell.Style.BackColor = Color.White
DC.ReadOnly = False
End If
cell.Style.ForeColor = Color.Blue
DC.DisplayIndex = DataList.TableColumns.Rows(DC.Index).Item("Orde") - 1
DC.AutoSizeMode = DataGridViewAutoSizeColumnMode.None
DC.Width = DataList.TableColumns.Rows(DC.Index).Item("Width")
DC.HeaderText = DataList.TableColumns.Rows(DC.Index).Item("Caption")
Select Case DataList.TableColumns.Rows(DC.Index).Item("Align")
Case 1
cell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
Case 2
cell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
Case Else
cell.Style.Alignment = DataGridViewContentAlignment.MiddleLeft
End Select
cell.Style.Format = "#0.00"
DC.CellTemplate = cell
Next
DGV.AllowUserToResizeColumns = True
DGV.AllowUserToResizeRows = False
The first time the code works just fine, but after selecting an other list the formatting is not working, then I select the same second list and then it works fine again.....
any suggestions ?
Thanks...
|
|
|
|
|
Interesting. Kschuler(sp?) is having an issue with a mousepointer not working when a user clicks on a column to sort. I wonder if these to issues are related. If there's an inherit problem with the grid loosing formatting after a user clicks the column header, that could cause the cursor to not update as well :/
I don't have any suggestion at the moment, but I'll do some testing and try to recreate the problem. What version of VS are you using?
|
|
|
|
|
Hello,
I'm using VB 2005 express edition. The database is Mysql
The first 3 columns in both list are the same, and there I have the same formatting as in the previous list
so it is like the grid keeps the same celltemplate from the previous list, but the caption is changed
|
|
|
|
|
I want to sort the database in ascending order! how can i make this happen with a button click event? can someone help me please??
Adrian De Battista: .Net Programmer, Java Programmer and Web Designer.
|
|
|
|
|
Typically sorting that is done with a mouse click isn't done by the server. Usually it's done by the container that is displaying the information. Typically a container will have a sort function built in to it. If it doesn't you can add a function to sort the Dataset taht's attached to it, then refresh the container.
If you're wanting to pull the information from the database presorted, then add " ORDER BY " and then the field name you want it sorted on. You can Default is Asc, however you can add "DESC" to the end to get reverse order.
|
|
|
|
|
First of all fill the dataset from the database
Dim myView as DataView
myView = ds.Tables("Customers").DefaultView
Here I am creating a DataView called myView, and assigning the results of the query (ds.Tables("Categories").DefaultView) to it.
You would create sort property by an 'Order By' clause in a SQL query. In an 'Order By' clause, what you're doing is ordering the ouput display by a field or fields in the database, in either Ascending or Descending order. If you add 'DESC', for descending, the default is 'ASC', so you really don't need to address this if your needs are fulfilled with the display results in ascending order.
All you really need to do to sort your dataview is to assign the field or fields you need sorted to the 'Sort' property, like this:
myView.Sort = "Region"
So, to sort by multiple fields, in a Descending order, you'd do it just like you would in an 'Order By' clause:
myView.Sort = "Region, City DESC"
Kumar Prabhakar
|
|
|
|
|
Hi,
I'm working with a sqlserver database & i extract records from it to my application built in vb.net
i have finishid my small app. but now i need to complete my deployement
i have deployed it , not completly because i didn't understand somethings like why adding a key in register & some stuffs
but i had a .msi file & everything is going ok
now i want to know how to take the database with me i mean with the application or with the .msi file
i will give an example to make is more clear
supposing i have my database in "C:\MyDataBase"
now each time i want to install my application in an other PC i have to copy this Data files & past them in the same root "C:\MyDataBase" in the other PC
now i'm asking if it is a possibility to do that just in vb i don't know , sepecifying a root or something like that & then once i install ma application the data files will take there position & i won't have problems in the programme
an other thing , actualy i didn't like the standar forms given with deployement project i want to built my own ones can you tell me how ??
thank you very very much , i hope you undertood that stupide english
try to be good if you can't be the best
|
|
|
|
|
I don't know how to create your own forms for deployment, but I am currently working on a program with a similar database situation. In a setup project bring up the File System Editor. On the side you will see a list of folders including Application Folder, User's Desktop, and User's Programs Menu. What ever you put in these folders will appear in their respective places. This is how you can specify during setup that you want to place a shortcut on the user's desktop for your program, etc. I use the Application Folder as a location for my database and the final .exe of my application. Then, in the code of my application, when I need to setup the connection for my database I use the following code to find the folder my application resides in (which is the same as the database):
My.Computer.FileSystem.GetParentPath(Application.StartupPath) & "MyDatabaseName.mdf"
Hope this helps.
|
|
|
|
|
the easiest way to create custom installation programs is to get DevStudio from InstallShield. Visual Studio used to ahve a copy that worked with C++. I haven't seen it with VS 2005(but I haven't looked that closely either). As far as customizing the setup wizard that comes with VS, it's very limited.
|
|
|
|
|
well , thanks i got all the first paragraph but actualy what i didn't get is that line :
My.Computer........
this is how we declare a connection object :
Public Con As New SqlConnection("workstation id=ORDI_AMINE;packet size=4096;integrated security=SSPI;data source=ORDI_AMINE;persist security info=True;initial catalog= GHotel")
now can you tell me how to do that
i added the two files "MyDataBase.Mdf" & "MyDataBase.Ldf" to application folder in an other folder that i had created in & i named it Data
so now i have ApplicationFolder\Data\"MyDataBase.Mdf" & "MyDataBase.Ldf"
tell me please how to make that work
GHotel : is My Data Base
ORDI_AMINE : is the name of ma PC
aahhh !! i forgot , i tried to write localhost instead of ORDI_AMINE & it doesn't work
please try your best with thanks
try to be good if you can't be the best
|
|
|
|
|
Sorry....I should have specified that the My.Computer....code only works in Visual Studio 2005. To do this in Visual Studio 2003 you can use this:
System.IO.Path.GetDirectoryName([Assembly].GetExecutingAssembly().GetName().CodeBase)
But you will need to include Imports System.Reflection
I'm not familiar with your method of creating a connection. Whenever I make a connection object I give it the full file path to the database file. Like in this connection string:
<br />
strDataBaseLocation = "C:\Program Files\MyApplicationData\MyDataBase.mdf"<br />
strConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename='" & strDataBaseLocation & "';Integrated Security=True;Connect Timeout=30;User Instance=True"
But since users may want to install to a different location, I just make sure that my database is always in the same relative location to my .exe.
Does this help you any? I just don't understand how your program knows where your database file is without the full path in the connection object.
|
|
|
|
|
Oh yeah sure i learned a new way to declare connection thank you
but actualy the f***en problems stills the same it doesn't want to work
i think it want to jock i will break the f***en mind of this PC
actualy i don(t understand too how it can know the way of the database without giving it the location
but i think it knows the server & the server show the way to this stupide programme
well i will thank you a lot if you can speak all the code you wrote abt that new classes & assemlies & stuffs plus i want to tell you that i added the two files Mdf & Ldf
to the application file in the deployement project
i hope this will work later when we know how to tell him to attach a database
i hope you want to help me & thank you for all what you did for me
try to be good if you can't be the best
|
|
|
|
|
I have a DataGridView control in a Windows Application project with the first three columns being image columns. (They contain icons for navigating to other forms for editing, viewing, and deleting) There isn't a property to set on these columns for changing the cursor from the default arrow into a hand, so I wrote the following code to manually make that happen:
Private Sub gvMast_CellMouseEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles gvMast.CellMouseEnter
Select Case e.ColumnIndex
Case 0, 1, 2
Select Case e.RowIndex
Case -1 'Header row
Cursor = Cursors.Default
Case Else
Cursor = Cursors.Hand
End Select
Case Else
Cursor = Cursors.Default
End Select
End Sub
Private Sub gvMast_CellMouseLeave(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles gvMast.CellMouseLeave
Cursor = Cursors.Default
End Sub
The problem I'm having is that after the user sorts a column by clicking in the header row of the DataGridView, this code doesn't work anymore. The cursor remains the default arrow. Debugging is a mess because everytime you hit a breakpoint you will hit the CellMouseLeave event, but it appears to be hitting the code that sets the hand cursor.
Anyone have any ideas?
|
|
|
|
|
Your code looks good. Is it possible that your sort is causing you to loose focus on the gridview? The way I get around break points is to fire a Messagebox.show method with the information I'm looking for.
Add: Messagebox.show(e.columnIndex + vbCrLf + e.RowIndex) into your cellmouseenter event and that will get the values displayed before you leave it. That will at least let you know what values are being passed to it. If none are being passed, then your control isn't capturing the mouseenter and mouseleave events.
|
|
|
|
|
Using a messagebox doesn't work either, since after you click okay on the messagebox it hits the cell mouse enter method again...creating a loop. But working off this idea I added code to change the text of a label instead. Every place I changed the cursor in code I added a different message to change the label text to. It appears as though it is hitting all of the code correctly, it is just not displaying the hand cursor. (My label text gets changed to the word "HAND" appropriately)
I'm still at a loss.
|
|
|
|