Message pop up? - vb.net

What is the way to implement/mimic the Windows message popup that a user gets when, for instance when you try to rename a folder on the desktop using invalid characters?
I want to use this method in lieu of a message box.

You can achieve this by using ErrorProvider. It is located in your toolbox. Just drag and drop it into your form. To use it, example code
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
If TextBox1.Text.Trim().Length > 6 Then
ErrorProvider1.SetError(TextBox1, "Input is too long!")
End If
End Sub
Method 2 : Using ToolTip. This can be found in your toolbox as well. Just drop it into your form and in the properties window, you can set the "tip" for each controls in your form.
Here is how it will look like when your cursor is hovering the controls.
If you dislike the rectangle pop up, you can change it to a ballon pop up by isBallon = true.

Related

How to hide a DataGridViewButtonCell

I have a DataGridViewButtonCell in my DataGridView and I wanted to set the property Visible to True.
I have tried:
DataGridView1.Rows("number of row i want").Cells("number of cell i want").Visible = True
Unfortunately it says that the property visible is read only.
Here is the code:
Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
'does not work
DataGridView1.Rows(e.RowIndex).Cells(6).Visible = True
End Sub
Does anyone knows how I can achieve this?
Thanks.
There is no actual way to hide a DataGridViewButtonCell. Currently I can only see two options:
Use padding to move the button over as shown here. I will provide similar VB.NET code
Set the Cell to a DataGridViewTextBoxCell and set the ReadOnly property to True
Use Padding:
Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
If DataGridView1.Rows(e.RowIndex).Cells(6).GetType() Is GetType(DataGridViewButtonCell) Then
Dim columnWidth As Integer = DataGridView1.Columns(e.ColumnIndex).Width
Dim newDataGridViewCellStyle As New DataGridViewCellStyle With {.Padding = New Padding(columnWidth + 1, 0, 0, 0)}
DataGridView1.Rows(e.RowIndex).Cells(6).Style = newDataGridViewCellStyle
End If
End Sub
Use DataGridViewTextBoxCell:
Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
If DataGridView1.Rows(e.RowIndex).Cells(6).GetType() Is GetType(DataGridViewButtonCell) Then
Dim newDataGridViewCell As New DataGridViewTextBoxCell
DataGridView1.Rows(e.RowIndex).Cells(6) = newDataGridViewCell
newDataGridViewCell.ReadOnly = True
End If
End Sub
Both of these should give you the effect of not showing the button.
This is really a perspective issue. From a programmer’s perspective, simply ignoring the button clicks on the buttons I want to disable is very easy to do and takes just a few lines of code.
From a user perspective, this situation would play out like this… the user clicks what appears to be a valid enabled button, and nothing happens. The user did not write the code for this… so at best the user will think the computer is not responding to the button click or at the worst… would think your coding skills are dubious!
The same situation happens if the button is missing. The user is not going to know why it is missing… but will most likely come to the same conclusion described above with a non-working button.
In another very simple approach, let say that all the buttons are enabled and we have a list of the button indexes we want to disable. The users presses one of the buttons, we check the disabled button list and if the clicked button is one that is disabled, simply display a message box to indicate why this button is disabled. This approach says to the user… “Here are a bunch of buttons, guess which ones are enabled”…
The DataGridViewDisableButtonCell and DataGridViewDisableButtonColumn wrappers solve all of the above issues… the button is visible so the user wont question where the button went if you set it to invisible and it is greyed out. “Greyed out” is something most users understand and will relieve the user of having to “guess” which buttons are enabled.
You can create a wrapper for two classes: the DataGridViewButtonCell and the DataGridViewButtonColumn.
The link How to: Disable Buttons in a Button Column in the Windows Forms DataGridView Control to the MS example is one I have used before using C#, however there is a VB implementation at the link also.
Below is a picture of the result of using the two wrappers described in the MS link. For testing, the picture below uses the check boxes to left of the button to disable the button on the right.
IMHO, using this strategy is user friendly. If you simply make the button invisible or read only, then the user is possibly going to think your code is messed up and not have a clear understanding of WHY the button is missing or doesn’t work. A disabled button indicates to the user that the button is not available for that item. An option would be to have a mouse roll-over indicating why the button is disabled.

How to connect Radiobutton to a textbox?

I'd like to create sample applications, like examination system. I don't know how to connect radio button and textbox to create multiple choices in this system. So can anyone can tell me how to connect radiobutton and textbox to create multiple choices?
If i understand your question correctly:
Radio buttons have 'text' property, you can put your description there.
Next, this code should place this Text description in TextBox after clicking this particular RadioButton:
Private Sub RadioButton_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton.CheckedChanged
TextBox.ext = RadioButton.text
End Sub
If not, you can always look for answer here:
https://www.tutorialspoint.com/vb.net/vb.net_radio_button.htm

Select and Show new Tab on control when values in txtbox change, but keep focus on txtbox

I'm having this issue that should be pretty easy to solve but I just can't seem to figure it out or find an answer yet. I have the following code:
Public Sub NotifyThatValuesChanged(sender As Object, e As EventArgs)
APIUserForm_MAIN.OnSecurityInputValuesChanged()
APIUserForm_MAIN.MessageSender.TabControl.SelectTab(0)
End Sub
So, I'm rasing events when values within txtboxes change, and one of the things I want to do is change tab focus when these values change, which it is doing...but....I don't want the cursor (or focus) to change to the selected tab. I want the cursor/focus to stay where it is at while this event happens, and for the tab selected on this other control to change from (1) to (0).
Thanks for the help!!!!
I don't think it's 100% possible. Try putting the focus back into the textbox:
Public Sub NotifyThatValuesChanged(sender As Object, e As EventArgs)
APIUserForm_MAIN.OnSecurityInputValuesChanged()
APIUserForm_MAIN.MessageSender.TabControl.SelectTab(0)
TextBox1.Select()
End Sub
If multiple controls are calling this method, you can use the sender parameter:
DirectCast(sender, Control).Select()

VB.net strange textbox behavior

A customer of mine is having a problem with a text box. When he clicks on the string in the text box the cursor always jumps to the end of the string. This is a standard VB.net 2005 text box with multi-line true. On my development machine it works correctly. I click in the middle of a string and can edit where I click. Can anyone suggest what is wrong?
He has run the program both under terminal server and locally on his lap top and has the same problem.
TIA,
John
Is it possible to observe the user? For example, the user might be pressing shift-tab when they are past the text-box, and refering to that as "clicking" the text box.
You can always force behavior like:
Private Sub TextBox1_GotFocus(sender As Object, e As System.EventArgs) Handles TextBox1.GotFocus
TextBox1.SelectionStart = 0
End Sub

Showing List of combobox while getting focus (vb.net)

When we click on drop down combobox control in our windows form, it shows the list automatically.
But when we press tab and navigate to that control from keyboard it doesn't shows the list automatically. So in other to show the list automatically on receiving focus what should be done?
Set the DroppedDown property of the combobox equal to true.
Private Sub myComboBox_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles myComboBox.GotFocus
myComboBox.DroppedDown= true
End Sub
I would like to mention on thing here.
I used Enter event to show Drop down list with DroppedDown=true,
But When I type something in text area of combobox and if i leave the area to next control, entered text is lost.
My combobox is databound.