|
Dear All,
I am a beginner of VB and I am trying to create a Confirmation Message for a particular checkbox.
The scenario is that: suppose I have two (2)checkboxes and one Submit button.
If I just want to display a confirmation for the checkbox #1 only. The user changes the status on checkbox 1 (on/off), then click on the Submit button, this confirmation will display.
Would you please help me out.
I would appreciate it.
|
|
|
|
|
I'm not sure I understand the question completely. If you want to always display a confirmation message if it is checked, that's pretty straight forward. If you want to display a confirmation message if the value has changed you will have to create a variable to record if it has changed or not. I would use a boolean value which is originally set to false and is set to true only in the CheckChanged event of the checkbox in question. The code for the confirmation box would look something like this:
Dim result As New DialogResult<br />
result = MessageBox.Show("Are you sure?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)<br />
Select Case result<br />
Case Windows.Forms.DialogResult.Yes<br />
'Code for Yes action<br />
Case Windows.Forms.DialogResult.No<br />
'Code for No action<br />
End Select
Of course, you have a lot of options here. Use the intellisense help to see the different combinations of buttons and other options that you can use.
This code was written in Visual Studio 2005, but if you use a different version it should still be very similar. Hope this helps.
|
|
|
|
|
Dear Kschuler,
I am so glad to receive a message from you. However, let me clear my problem so that you can get it fully.
Suppose a user is modifing a form that have 2 checkboxes (checkbox1 and checkbox2) and 1 submit button.
If a user change (check or uncheck) the checkbox1, then a confirmation will display.
That is my problem, and I am using VB6. Would you please help me out.
I would appreciate your help very much,
Tram88
|
|
|
|
|
Okay, how about this:
Private boolChanged As Boolean
Private Sub Form_Load()
boolChanged = False
End Sub
Private Sub btnSubmit_Click()
Dim result As VbMsgBoxResult
If boolChanged = True Then
result = MsgBox("Are you sure?", vbYesNo, "Confirm")
Select Case result
Case VbMsgBoxResult.vbYes
'Code if user selects Yes
Case VbMsgBoxResult.vbNo
'Code if user selects No
End Select
Exit Sub
End If
'Code if no changes were made to check boxes
End Sub
Private Sub Check1_Click()
boolChanged = True
End Sub
Private Sub Check2_Click()
boolChanged = True
End Sub
|
|
|
|
|
Dear Kschuler,
Would you please confirm the codes that you wrote above, Should I put it into the .acsx or ascx.vb file? I would appreciate your potential helps very much.
Tram88
|
|
|
|
|
Sorry...I assumed that you were creating a standard Windows Forms Application. This code will not work for a web project, and I am not sure I can help with a VB6 web project. I typically use VS2003, 2005.
To perform your task in a web project I would probably set a hidden control on the page to record if the checkbox changes. Hidden controls look like this:
<input id=hidChanged runat=server type=hidden />
(You will need another hidden control to store whether the user selected yes or no on the confirm if that determines which code to use later in the code behind) Then I would attach a javascript function to the button which would check the hidden variable and display a javacript confirm if needed. The javascript would look something like this:
function CheckIfChanged()<br />
{<br />
if (hidChanged.value <> "")<br />
{<br />
Result = confirm("Are you sure?");<br />
if (Result)
{<br />
form1.hidResult.value = "Y";<br />
return true;<br />
}else{
form1.hidResult.value = "";<br />
return false;<br />
} <br />
}<br />
}
The javascript would need to be connected to the button's on click event.
Then of course, you need to set the hidden variable when ever a user clicks the checkbox. You can do this in code behind if it's okay to do a postback everytime the user clicks the checkbox, or you could use more javascript.
I'm not sure how much of this applies to VB6, but I hope it will help you or at least give you some ideas to work from. Sorry I couldn't help you more.
|
|
|
|
|
Dear Kschuler,
Thank you very much for your potential helps.
Tram88
|
|
|
|
|
How would you add preview support to a screen-saver you write in VB.Net?
|
|
|
|
|
I am looking to for Visual Basic code (using Visual Studio 2005 and a Visual Basic Smart device Pocket PC 2003 project option) that will allow me to open the serial port of a Pocket PC. I need the code that will open and then read GPS data when the built project is deployed to the Pocket PC. The GPS uses COM1 at a baud rate of 4800. I have only been able to find third party addons and these tend to be expensive. As a pensioner I cannot afford to buy these addons and also wish to do it without any extras if this possible so I do not have to rely on third parties. I would be very grateful if someone can email me with the answer to my problem (datacore@nildram.co,uk)
Gordon
|
|
|
|
|
How can i copy file from a server?
This is without any kind of sharing.
i used this:
System.IO.File.Copy("soucePath", "detpath")
but return this message:
Could not find file "sourcepath"
and in the file system the file is in here.
thank for all!
Kosta
|
|
|
|
|
The credentials under which you are running must permit access to the source path - whatever its form.
This implies some sort of sharing even if it is at the administrator level (i.e. the 'hidden' C$, D$ etc admin shares).
Having said that, how about showing us the exact code you are using (use copy/paste) and the values of any variables used in the copy function?
...Steve
1. quod erat demonstrandum
2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once
|
|
|
|
|
hi . i wnat make combobox like treeview and set datasource to a table Products(
123
|
|
|
|
|
How to disable button in the ContentMenu for
certain user.
I mean, lets say in the login form i have this
particular user ADMINISTRATOR, MANAGER, & EXECUTIVE.
For the user list button i only want to allow
ADMINISTRATOR to view it.??
by the way, thanks a lot for the [View Tab] help.
The code works...
|
|
|
|
|
You need to create roles and demand permissions. Create a Principal permission based on their user and then demand it.
Dim myPermission1 as new PrincipalPermission("ADMINISTRATOR", Nothing)
Dim mypermission2 as new PrincipalPermission("MANAGER", Nothing)
Dim myPermission3 as new Principalpermission("EXECUTIVE", Nothing)
Dim myPermission as PrincipalPermission
Try
myPermission.demand
button1.enabled = true
Catch
'If they're not in the ManagerGroup it won't run the enabled = true command
End Try
|
|
|
|
|
My application runs excel 2000 as an automation server. Problem is I cannot get excel to release from the windows processes after the application finishes. I've done internet searches but have not found any thing that works. Any help would be greatful. Thanks.
|
|
|
|
|
hi all,
I'm having a bit of an issue here and maybe one of you guys can help me out .
I'm looking for a way to return all COMPONENTS in a form during run-time, and i mean components including all controls , menu's, custom controls etc.
As you all now a control is a component but a component is not a control.
You will probably think that i'm somesort of idiot , but i'm not (at least i think i'm not), and i've tried every possible way to reach my goal:
1) tried to convert the form as container -> didn't work
2) adding the component that needs to perform above actions and using it's own container as componentcollection holder doesn't work, bcause the container returned is the component itself.
3) returning a menu's container -> doesn't work -> it always returns nothing
batmike2000
|
|
|
|
|
There may be an easier answer than just digging up one for this. What's the final goal you're trying to reach?
|
|
|
|
|
Hi leeland,
the final goal to achieve is a complete component and control iteration of a form to disable /enable them and make them in-/visible if demanded. But this in a dynamic way, cause i never can tell in advance what will be on the Form.
kr.
batmike2000
|
|
|
|
|
tnx Leeland,
i've found the solution: i needed to use reflection
<br />
strFormName = param_Form.Name<br />
<br />
Dim param_Form_type As Type = param_Form.GetType()<br />
Dim compFields As FieldInfo() = param_Form_type.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic)<br />
For Each fiField As FieldInfo In compFields<br />
Dim strCtrl(1) As String<br />
strCtrl = ReturnCompName(fiField, param_Form)<br />
For Each dr As DataRow In myrs.Rows<br />
If strCtrl(0) = dr("SecAuthCtrl_Name") And fiField.FieldType.FullName = dr("SecAuthCtrl_Type") Then<br />
Select Case fiField.FieldType.FullName.ToLower<br />
Case "System.Windows.Forms.ToolBarButton".ToLower<br />
Dim cmp As ToolBarButton = DirectCast(fiField.GetValue(param_Form), ToolBarButton)<br />
cmp.Enabled = dr("SecAuthorized_Enabled")<br />
cmp.Visible = dr("SecAuthorized_Visible")<br />
Case "System.Windows.Forms.MenuItem".ToLower<br />
Dim cmp As MenuItem = DirectCast(fiField.GetValue(param_Form), MenuItem)<br />
cmp.Enabled = dr("SecAuthorized_Enabled")<br />
cmp.Visible = dr("SecAuthorized_Visible")<br />
Case Else<br />
End Select<br />
End If<br />
Next<br />
Next
this works now,
tnx for your effort
batmike2000
|
|
|
|
|
Hi,
In my client application,it requires to access a file in the remote server station within LAN, which requires authentication(User name and password)in VB. Provide me any sample code that has code to authenticate remote PC file access.I am not using ASP or VB.NET.
|
|
|
|
|
|
Hi,
is there a way to prevent highlighting of the selected row in a datagridview? i want to create a usercontrol like the one in the ntfs security tab in the file properties dialog in the windows explorer.
thx
|
|
|
|
|
|
|
I had this same problem once, and I never really figured out a good way to do it. I ended up kinda cheating and just setting the selection highlight to the same color that the row was already. You can set the default row highlight and the alternating row highlight if you use different colors for alternating rows. Here's the code I used:
MyGridView.DefaultCellStyle.SelectionBackColor = Color.White<br />
MyGridView.DefaultCellStyle.SelectionForeColor = Color.Black<br />
MyGridView.AlternatingRowsDefaultCellStyle.SelectionBackColor = My.Settings.ContrastBackColor<br />
MyGridView.AlternatingRowsDefaultCellStyle.SelectionForeColor = My.Settings.ContrastFontColor
Let me know if you find a nicer way!
|
|
|
|