|
I mostly use classes, but there are some controls, so I'll go for your suggestion with the dropdowns.
Thanks a lot Dave, I really appreciate your helt
best regards
Andy
|
|
|
|
|
Experts,
I have a textbox which will generate a set of random numbers, e.g 10 , 4 , 6 , 3 , 2 , 1 ....
What i need to do is to basically split this textbox up into lots of textboxes. I was originally using e.g
txt1.text = mid(txt0.text, 1,txt0.textlength - 7)
this was ok if you where using numbers below 10 but now i am not, so i have split my numbers using commas but how do i sort them into the differnet text boxes using the commas as splitting points?
Many thanks
Dan
|
|
|
|
|
string.Split() is the prime choice for splitting strings by a special character of your choice.
BTW: you would get into trouble if your numbers would exceed 999, your numbers include thousands separator, and your app were used by people using comma as a thousands separator (lots of West-European countries do this).
|
|
|
|
|
Hi Dan, How's it going. Why don't you generate your list of random numbers into a List(of Integer). Then you can use the List(of Integer) to populate the rest of the text boxes. That way you don't need to split anything. Start using the powers of the .Net Framework and you will find programming so much easier, I promise.
Cheers
Wayne
|
|
|
|
|
I'm using webclient or web.downloaddata to download a url. Sometimes the correct source isn't downloaded (same thing happens with webclient or web.downloaddata), although it always appears properly from a browser. Randomly, some parts of the source is not downloaded. Any ideas would be appreciated.
|
|
|
|
|
A single file, or multiple? Could it be that the server is redirecting some parts of the download to another server?
I are Troll
|
|
|
|
|
This is a piece of code that i am using to test a possible solution to a given problem.
Dim x As Button
x = New Button
AddHandler x.Click, AddressOf ClickSubRoutine
x.Name = ButtonText
x.Location = New Point(x + 100, y)
Me.Controls.Add(x)
The problem is that i have a button control on the form, when a user clicks on this button many other buttons are created from a list in a file.
AddHandler x.Click, AddressOf ClickSubRoutine
My question is how can i assign the handler to a function name defined from this list without having to do some if name = statements? is it possible?
Thanks
Simon
Thanks for taking the time, now go away and grow up and return in a newer, more polite and less shouty and ignorant form. - Dalek Dave
|
|
|
|
|
To be honest, I don't fully understand what you are asking here, but if i get it ,then you want to create a load of buttons on the fly, from a list kept in a text file or something similar, and you also want each button created to have the same click event. To do this does not require the name of the control as you need to assign the handler when the button is created. Open up a new project and put a button on the form. In the buttons click event put the following code
Dim index As Integer = 0
Dim intHeightDiff As Integer = Button1.Height + 5
For Each ButtonName As String In lstButtonNames
Dim btnNew As New Button
btnNew.Name = lstButtonNames(index)
AddHandler btnNew.Click, AddressOf ClickRoutine
btnNew.Parent = Me
btnNew.Visible = True
btnNew.Top = intHeightDiff + (intHeightDiff * index) + Button1.Top
btnNew.Left = Button1.Left
btnNew.Width = Button1.Width
btnNew.Text = btnNew.Name
index += 1
Next
then create the function that you want to assign to all the buttons
Private Sub ClickRoutine(ByVal sender As System.Object, ByVal e As System.EventArgs)
MsgBox(CType(sender, Button).Name)
End Sub
that should give you a load of buttons all with the same click handler
|
|
|
|
|
Sorry about the clearness of the question
what i want to do on the fly is build up some buttons, but apply and addhandler to a specific function
for example
button1 will execute code at function1
button2 will execute code at function2
button3 will execute code at function1
but the names and function names will be determined at runtime.
I hope this is more clear for you and thanks for helping
|
|
|
|
|
I think I get the idea. How about this. Create a class called, say, MyButton like so ,
Private Class MyButton
Private strName As String
Private strFunction As String
Public Property Name() As String
Get
Return strName
End Get
Set(ByVal value As String)
strName = value
End Set
End Property
Public Property MyFunction() As String
Get
Return strFunction
End Get
Set(ByVal value As String)
strFunction = value
End Set
End Property
End Class
on your form declare a list of these to collect your data into, call it buttons. Fill up the list maybe in your form Load event like this
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Buttons = New List(Of MyButton)
For i As Integer = 0 To 4 'obviously get your info from file but i created this for demo
Dim newButton As New MyButton
newButton.Name = "Button " & i
If i Mod 2 = 0 Then newButton.MyFunction = "ClickRoutine1" Else newButton.MyFunction = "ClickRoutine2"
Buttons.Add(newButton)
Next
End Sub
create the functions that are needed by the buttons i.e
Private Sub ClickRoutine1(ByVal sender As System.Object, ByVal e As System.EventArgs)
MsgBox("Presented to you by ClickRoutine1 through " & CType(sender, Button).Name)
End Sub
Private Sub ClickRoutine2(ByVal sender As System.Object, ByVal e As System.EventArgs)
MsgBox("Presented to you by ClickRoutine2 through " & CType(sender, Button).Name)
End Sub
then in your Button1 click event you create the buttons like this
that should get you where you want to go I think,
|
|
|
|
|
Thank you Zim,
you've saved me loads of hair pulling it worked
Thanks for taking the time, now go away and grow up and return in a newer, more polite and less shouty and ignorant form. - Dalek Dave
|
|
|
|
|
A pleasure. Glad I could help.
|
|
|
|
|
You can do this a bit more cleanly by storing the delegate in MyButton .
Private Class MyButton
Private strName As String
Private clkHandler As System.EventHandler
Public Property Name() As String
Get
Return strName
End Get
Set(ByVal value As String)
strName = value
End Set
End Property
Public Property Handler() As System.EventHandler
Get
Return clkHandler
End Get
Set(ByVal value As System.EventHandler)
clkHandler = value
End Set
End Property
End Class
Private Sub ClickRoutine1(ByVal sender As System.Object, ByVal e As System.EventArgs)
MsgBox("Presented to you by ClickRoutine1 through " & CType(sender, Button).Name)
End Sub
Private Sub ClickRoutine2(ByVal sender As System.Object, ByVal e As System.EventArgs)
MsgBox("Presented to you by ClickRoutine2 through " & CType(sender, Button).Name)
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Me.Load
Buttons = New List(Of MyButton)
For i As Integer = 0 To 4
Dim newButton As New MyButton
newButton.Name = "Button " & i
If i Mod 2 = 0 Then
newButton.Handler = AddressOf ClickRoutine1
Else
newButton.Handler = AddressOf ClickRoutine2
End If
Buttons.Add(newButton)
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
Dim index As Integer = 0
Dim intHeightDiff As Integer = Button1.Height + 5
For Each newButton As MyButton In Buttons
Dim btnNew As New Button
btnNew.Name = newButton.Name
AddHandler btnNew.Click, newButton.Handler
btnNew.Parent = Me
btnNew.Visible = True
btnNew.Top = intHeightDiff + (intHeightDiff * index) + Button1.Top
btnNew.Left = Button1.Left
btnNew.Width = Button1.Width
btnNew.Text = btnNew.Name
index += 1
Next
End Sub
|
|
|
|
|
Nice.
I might be hijacking this with a followup question, so sorry in advance if this is a no-no...
Could this be taken a step further by getting rid of the if / case part where the AddressOf is attached?
That way it would become even more robust seeing the code will need no further modification to incorporate new handlers.
It might be simple but I just don't see it yet (mainly because I didn't sleep enough and the whole office is smelling of paint)
|
|
|
|
|
The OP originally stated that he was getting the info from a file. I assumed it was a text file where the name of the button was stored together with it's function name, and that they would be retrieved in one operation, and then assigned on the fly. In the form load event in the examples sited by me, the if i mod 2 ... was used for demo purposes only. In Gregorys example, where he assigns an eventhandler directly to a property, you would still need to decide, when you retrieve the info from the file, what function is the right one, as all you have is a string representing the name of the function, and not an instance of the function itself, if you get me. Therefore you would still need to put in the Select Case On Assignment
. To illustrate this, Take this example
So in essence there is really no difference between the way Gregory and myself implemented this.
Happy Coding
|
|
|
|
|
No discussion about the intent of the OP, or the differences between your example and the one by Gregory.
Where to retrieve the info from wasn't my concern, I might not have made that clear. It was more to find a way to make the Routines configurable as well. Although the paint smell in the office is still heavily present, found that Reflection puts me on the way quite well...
Dim lobj As Object = Activator.CreateInstance(Type.GetType("DummyLib.clsTestingTheStateHandler,DummyLib"))
Dim lass As Reflection.Assembly = Reflection.Assembly.Load("DummyLib")
Dim ltype As Type = lass.GetType("DummyLib.clsTestingTheStateHandler")
Dim lmi As Reflection.MethodInfo = ltype.GetMethod("ThisIsTheHandler")
Dim lblnState As Boolean = DirectCast(lmi.Invoke(lobj, New Object() {phtParameters}), Boolean)
Do you know of possible other alternatives to achieve something along these lines?
Enjoying the coding
|
|
|
|
|
If you want to avoid using AddHandler and RemoveHandler manually, you can create a class for your button which includes appropriate event handlers and one or more delegates supplied by the parent which should be invoked when the button is pushed. These delegates could take parameters beyond what would normally be supplied in a Click event.
|
|
|
|
|
Hi,
have a site login screen to come will have to open a popup.
Directs itself to the main page. "Giriş" button when the login screen comes.
site address is "https://ebeyanname.gib.gov.tr/giris.html"
site source code;
|
|
|
|
|
Hi,
I have a datagrid where I add a checkbox column that is not part of the database structure. the state of the checkbox is true initially, I try to change it to uncheck, nothing happens..How can I change a checkbox inside a datagrid from true to false, vice verca? also when I check a row, the record from that particular row loads to another form for other porcess.
Using Vb.net
Thanks in advance..
modified on Wednesday, April 28, 2010 1:55 PM
|
|
|
|
|
Take a look at the thread containing this[^] answer to see if it matches your situation.
Good luck!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Assume that you load a table into the datagrid. It has some column like id, name, address etc. You add a checkbox into the datagrid using grid template. So if you want to fill / get bool value you need to do something like:
foreach (GridViewRow row in datagridView.Rows)
{
CheckBox cbYesOrNo = (CheckBox)row.FindControl("cbYesNo");
if (cbYesOrNo.Checked)
{
}
else
{
}
}
Thanks
Md. Marufuzzaman
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
Hi,
Initially the checkbox in the datagrid is set to true..when i click on it nothing happens..i want to be able to change the state of the checkbox on click..that is set to true or false
then do something on the record that is checked..
thanks,
|
|
|
|
|
Experts,
I have a web browser in vb.net, works like a treat
However is there any way that on a button click in the html web page through vb.net, can i then have a button that is invisible in vb.net to be then be visible to the user on the vb page.
e.g the web page is shown but the user doesn't do any thing. - nothing happens
the user types something in - nothing happens on the vb side
the user types something in a presses the submit buttons - a vb button appears allowing them to continue.
Any ideas?
Dan
|
|
|
|
|
Hi,
you could;
1. modify the web page any way you like, it is available as WebBrowser.DocumentText
2. add JavaScript (assuming JS is enabled).
3. add/modify hyperlinks, possibly pointing to your own web site
4. provide an embedded HTTP server, which means your own web site could be embedded inside your app (see e.g. Sample HTTP Server Skeleton in C#[^])
|
|
|
|
|
It sounds like you have a WebBrowser component displaying some HTML embedded in a windows Form, and you want to respond to events that cause a postback in the web page in the windows form. I am assuming that is what you are getting at.
We have a similar thing where html is used to display details inside a windows form and hyperlinks cause a new windows form to pop up instead of navigating in the HTML.
We do this by handling the BeforeNavigate event of the browser and interrogating the URL requested. If the URL requires custom navigation in the windows application then we set e.Cancel = True to stop the default navigation continuing and instead run our own custom code.
It is all a bit messy, but that is the price for a hybrid windows/web solution.
|
|
|
|