Mimic radiobuttons in datagridview using DataGridViewCheckBoxColumns - vb.net

PLEASE NOTE: this question is about DataGridViewCheckBoxColumns inside a DataGridView control - not the normal CheckBox control.
I have a winforms app that contains a DataGridView with three checkbox (DataGridViewCheckBoxColumn) columns. I'd like to mimic radiobuttons ie. one, and only one, checkbox is checked at a time. I am able to turn off the other checkboxes in the grid when one is clicked as follows:
Private Sub dgvNormalReports_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvNormalReports.CellClick
If mblnSuppressUI Then Exit Sub
mblnSuppressUI = True
If e.ColumnIndex >= 0 And e.ColumnIndex <= dgvNormalReports.ColumnCount - 1 And e.RowIndex >= 0 And e.RowIndex <= dgvNormalReports.Rows.Count - 1 Then
Select Case dgvNormalReports.Columns(e.ColumnIndex).Name
Case "dclLeaveOnThisList", "dclPrintLetter", "dclNoLetterNeeded" 'mimic radiobutton - turn off other checkboxes
dgvNormalReports.Rows(e.RowIndex).Cells("dclLeaveOnThisList").Value = False
dgvNormalReports.Rows(e.RowIndex).Cells("dclPrintLetter").Value = False
dgvNormalReports.Rows(e.RowIndex).Cells("dclNoLetterNeeded").Value = False
'N.B. current cell's checked status is changed AFTER this event
Case Else
'ignore
End Select
End If
mblnSuppressUI = False
End Sub
The problem I am having is that if the user clicks on a checkbox that is already checked, it becomes unchecked, and then none of the three checkboxes are checked. I always want one (and only one) checkbox ticked at all times.

Use CurrentCellDirtyStateChanged event handler.
Private Sub dgvNormalReports_CurrentCellDirtyStateChanged(sender As Object, e As EventArgs) Handles dgvNormalReports.CurrentCellDirtyStateChanged
If Me.dgvNormalReports.IsCurrentCellDirty = True Then
If Me.dgvNormalReports.CurrentCell.OwningColumn.GetType() = GetType(DataGridViewCheckBoxColumn) Then
If Me.dgvNormalReports.CurrentCell.Value = False Then
'Update only if changed from false to true
If Me.dgvNormalReports.CurrentCell.OwningColumn.Name.Equals("dclLeaveOnThisList") = false Then Me.dgvNormalReports.CurrentRow.Cells("dclLeaveOnThisList").Value = False
If Me.dgvNormalReports.CurrentCell.OwningColumn.Name.Equals("dclPrintLetter") = false Then Me.dgvNormalReports.CurrentRow.Cells("dclPrintLetter").Value = False
If Me.dgvNormalReports.CurrentCell.OwningColumn.Name.Equals("dclNoLetterNeeded") = false Then Me.dgvNormalReports.CurrentRow.Cells("dclNoLetterNeeded").Value = False
Me.dgvNormalReports.CommitEdit(DataGridViewDataErrorContexts.Commit)
Else
'Prevent changes
Me.dgvNormalReports.CancelEdit()
End If
End If
End If
End Sub
If you have predefined columns in datagridview, then may be better will be used a generated by VisualStudio column objects:
Me.dclLeaveOnThisList.Name
Me.dclPrintLetter.Name
Me.dclNoLetterNeeded.Name

First step, edit your three DataGridView columns and set each columns property ReadOnly to true (this will prevent user from changing the values)
dclLeaveOnThisList
dclPrintLetter
dclNoLetterNeeded
and second, use the following code below
Private Sub dgvNormalReports_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvNormalReports.CellClick
If mblnSuppressUI Then Exit Sub
mblnSuppressUI = True
If e.ColumnIndex >= 0 And e.ColumnIndex <= dgvNormalReports.ColumnCount - 1 And e.RowIndex >= 0 And e.RowIndex <= dgvNormalReports.Rows.Count - 1 Then
Dim tmpColName As String = dgvNormalReports.Columns(e.ColumnIndex).Name
With dgvNormalReports.Rows(e.RowIndex)
Select Case tmpColName
Case "dclLeaveOnThisList", "dclPrintLetter", "dclNoLetterNeeded" 'mimic radiobutton - turn off other checkboxes
'Unchecked all checkboxes besides the selected one
If tmpColName <> "dclLeaveOnThisList" Then .Cells("dclLeaveOnThisList").Value = False
If tmpColName <> "dclPrintLetter" Then .Cells("dclPrintLetter").Value = False
If tmpColName <> "dclNoLetterNeeded" Then .Cells("dclNoLetterNeeded").Value = False
'Ensures that the selected cell is checked
.Cells(e.ColumnIndex).Value = True
End Select
End With
End If
mblnSuppressUI = False
End Sub

You can use a combination of these DataGridView events:
CellValueChanged
CurrentCellDirtyStateChanged
CellBeginEdit
You can use CellValueChanged instead of CellClick because CellClick event occurs when any part of a cell is clicked, including borders and padding (MSDN).
CurrentCellDirtyStateChanged event commit the change when the CheckBox is clicked.
The code in CellBeginEdit prevents user from modify a checked CheckBox.
This is an example:
Private Sub DataGridView1_CellValueChanged(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
With Me.DataGridView1
.CurrentCell.Value = True
If .Columns(e.ColumnIndex).Name = "dgvchkOptionA" Then
.Rows(e.RowIndex).Cells("dgvchkOptionB").Value = False
.Rows(e.RowIndex).Cells("dgvchkOptionC").Value = False
ElseIf .Columns(e.ColumnIndex).Name = "dgvchkOptionB" Then
.Rows(e.RowIndex).Cells("dgvchkOptionA").Value = False
.Rows(e.RowIndex).Cells("dgvchkOptionC").Value = False
ElseIf .Columns(e.ColumnIndex).Name = "dgvchkOptionC" Then
.Rows(e.RowIndex).Cells("dgvchkOptionA").Value = False
.Rows(e.RowIndex).Cells("dgvchkOptionB").Value = False
End If
End With
End Sub
Private Sub DataGridView1_CurrentCellDirtyStateChanged(sender As Object, e As System.EventArgs) Handles DataGridView1.CurrentCellDirtyStateChanged
If Me.DataGridView1.IsCurrentCellDirty Then
DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit)
End If
End Sub
Private Sub DataGridView1_CellBeginEdit(sender As Object, e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles DataGridView1.CellBeginEdit
With Me.DataGridView1
If .CurrentCell Is .Rows(e.RowIndex).Cells(e.ColumnIndex) And _
.CurrentCell.Value Then e.Cancel = True
End With
End Sub

Related

ComboBox Control within DatagridView

I want to use DGV as a table to take User’s inputs. And in few columns, I want User to select values from a collection hence I decided to use Comboboxcontrol. I selected a standard DGV ("DGV2") and a standard Combobox ("CBTest") as tools. And I programmed this Combo to appear on Columnindex 2 (when user enters the particular cell, Combo box pops-up). User can select from the combo items (Drop-Down-List) and after selection clicked done, curser moves to next column.
Now there is problems with UP/DOWN Keys when control is in cell having COMBO-BOX-
I am not able to control behavior of UP /DOWN Keys when user enters the Cell having COMBO Control.
Sometime with up-down keys cursor moves between Combobox items and sometimes it jumps in other rows.
I am a beginner so any hint and help will be useful.
Code I used -
Public Class frmSIDDGV
Dim nCol As Integer = 0
Dim nRow As Integer = 0
Private Sub frmSIDDGV_Load(sender As Object, e As EventArgs) Handles MyBase.Load
With DGV2
.AllowUserToAddRows = False
.AllowUserToDeleteRows = False
.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
.AutoResizeColumns()
.RowTemplate.Height = 40
.RowHeadersVisible = False
End With
DGV2.ColumnCount = 5
With DGV2
.Columns(0).Name = "Item"
.Columns(1).Name = "MRP"
.Columns(2).Name = "Qty"
.Columns(3).Name = "Unit"
.Columns(4).Name = "Amount"
End With
DGV2.Rows.Add()
DGV2(0, 0).Value = 1
End Sub
Private Sub DGV2_KeyUp(sender As Object, e As KeyEventArgs) Handles DGV2.KeyUp
If e.KeyCode = Keys.Enter Then
If ActiveControl.Name <> "CBTest" Then
If nCol = DGV2.ColumnCount - 1 Then
DGV2.Rows.Add()
DGV2.CurrentCell = DGV2(0, nRow + 1)
Else
DGV2.CurrentCell = DGV2(nCol + 1, nRow)
End If
End If
ElseIf e.KeyCode = Keys.Escape Then
If ActiveControl.Name = "CBTest" Then
CBTest.SelectedIndex = 0 : CBTest.Visible = False
DGV2.CurrentCell = DGV2(nCol, nRow)
DGV2.Focus()
End If
End If
End Sub
Private Sub DGV2_CurrentCellChanged(sender As Object, e As EventArgs) Handles DGV2.CurrentCellChanged
Try
nCol = DGV2.CurrentCell.ColumnIndex
nRow = DGV2.CurrentCell.RowIndex
Catch ex As Exception
nCol = 0
nRow = 0
End Try
End Sub
Private Sub DGV2_CellEnter(sender As Object, e As DataGridViewCellEventArgs) Handles DGV2.CellEnter
Select Case e.ColumnIndex
Case 2 ' User entered in Cell name "Item"
DGV2.Controls.Add(CBTest)
'DGV2.BeginEdit(True)
Dim oRectangle = DGV2.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, True)
CBTest.Size = New Size(oRectangle.Width, oRectangle.Height)
CBTest.Location = New Point(oRectangle.X, oRectangle.Y)
CBTest.Visible = True
SendKeys.Send("{F4}")
CBTest.SelectedIndex = 0
CBTest.Capture = True
CBTest.Focus()
End Select
End Sub
Private Sub CBTest_SelectionChangeCommitted(sender As Object, e As EventArgs) Handles CBTest.SelectionChangeCommitted
With DGV2
.Focus()
.Item(nCol, nRow).Value = Trim(CBTest.Text)
.CurrentCell = .Rows(.CurrentRow.Index).Cells(nCol + 1)
End With
CBTest.Visible = False
End Sub
End Class

Uncheck an item and "Select All" option from CheckedListBox on Windows Form

I have added a checkbox list with some names and a select all option. I am able to select all check boxes in checkbox list when I select (Select all) option.
Problem here is, I am not able to uncheck (Select All) option whenever I uncheck any of the options from check box list.
Below is the vb.net code attached for (Select All) functionality.
Private Sub ChkLB_dl_name_cb_ItemCheck(sender As Object, e As ItemCheckEventArgs) Handles ChkLB_dl_name_cb.ItemCheck
If e.Index = 0 Then
Dim newCheckedState As Integer = e.NewValue
For i As Integer = 1 to ChkLB_dl_name_cb.Items.Count - 1
Me.ChkLB_dl_name_cb.SetItemCheckState(i, newCheckedState)
Next
End If
End Sub
Below is an image of the checkbox list on the windows form, for your reference.
.
In general i would use a Boolean variable to avoid that this handler is called for every item that you change programmatically. This will also fix the problem that you cannot uncheck the first item:
Private updatingListProgramatically As Boolean = False
Private Sub ChkLB_dl_name_cb_ItemCheck(sender As Object, e As ItemCheckEventArgs) Handles ChkLB_dl_name_cb.ItemCheck
If updatingListProgramatically Then Return
If e.Index = 0 Then
updatingListProgramatically = True
For i As Integer = 1 To ChkLB_dl_name_cb.Items.Count - 1
Me.ChkLB_dl_name_cb.SetItemCheckState(i, e.NewValue)
Next
Else
Dim checked As Boolean = e.NewValue = CheckState.Checked
If Not checked Then
updatingListProgramatically = True
Me.ChkLB_dl_name_cb.SetItemCheckState(0, CheckState.Unchecked)
End If
End If
updatingListProgramatically = False
End Sub
The Else block seems to be what you are asking for.
Try adding an Else for the first 'If' condition and add a second 'If' statement to check if "Select All" Check box is Unchecked or not.
Private Sub ChkLB_dl_name_cb_ItemCheck(sender As Object, e As ItemCheckEventArgs) Handles ChkLB_dl_name_cb.ItemCheck
If e.Index = 0 Then
If ChkLB_dl_name_cb.GetItemCheckState(0) = CheckState.Unchecked Then
Dim newCheckedState As Integer = e.NewValue
For i As Integer = 1 To ChkLB_dl_name_cb.Items.Count - 1
ChkLB_dl_name_cb.SetItemCheckState(i, newCheckedState)
Next
End If
Else
ChkLB_dl_name_cb.SetItemCheckState(0, CheckState.Unchecked)
End If
End Sub
Like following you should get the desired functionality:
Private Sub ChkLB_dl_name_cb_ItemCheck(sender As Object, e As ItemCheckEventArgs) Handles ChkLB_dl_name_cb.ItemCheck
If e.Index = 0 Then
Dim newCheckedState As Integer = e.NewValue
For i As Integer = 1 To ChkLB_dl_name_cb.Items.Count - 1
Me.ChkLB_dl_name_cb.SetItemCheckState(i, newCheckedState)
Next
Else
'Remove the event-handler to prevent the ItemCheck-method from being called again
RemoveHandler ChkLB_dl_name_cb.ItemCheck, AddressOf ChkLB_dl_name_cb_ItemCheck
'If the item is being checked and all items are checked
'(except "Select All"), then check "Select All"
If e.NewValue = CheckState.Checked AndAlso
ChkLB_dl_name_cb.CheckedItems.Count + 1 = ChkLB_dl_name_cb.Items.Count - 1 Then
'Check "Select All"
ChkLB_dl_name_cb.SetItemCheckState(0, CheckState.Checked)
Else
'Uncheck "Select All"
ChkLB_dl_name_cb.SetItemCheckState(0, CheckState.Unchecked)
End If
'Re-Add the handler
AddHandler ChkLB_dl_name_cb.ItemCheck, AddressOf ChkLB_dl_name_cb_ItemCheck
End If
End Sub

Select only one checkbox from multiple checkbox in a row from DataGridView

I'm using DataGridView with DataSource from TableAdapter and add 5 unbound columns with type DataGridViewCheckBoxColumn .
They are : "lima","empat","tiga","dua","satu"
What I need to do, in the same row when checkbox "lima" is selected, the rest checkboxes become unselected or only can select one checkbox in the same row
Here's what I wrote down in CellValueChanged event :
Private Sub DataGridView3_CellValueChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView3.CellValueChanged
If DataGridView3.CurrentRow IsNot Nothing Then
Dim SelectedColumnName = DataGridView3.Columns(DataGridView3.CurrentCellValue.ColumnIndex).Name
If e.ColumnIndex = DataGridView3.Columns("lima").Index OrElse _
e.ColumnIndex = DataGridView3.Columns("empat").Index OrElse _
e.ColumnIndex = DataGridView3.Columns("tiga").Index OrElse _
e.ColumnIndex = DataGridView3.Columns("dua").Index OrElse _
e.ColumnIndex = DataGridView3.Columns("satu").Index Then
Dim Row = CType((CType(DataGridView3.DataSource.Current, DataRowView)).Row, DataRow)
If SelectedColumnName = "lima" Then
If DataGridView3.CurrentRowCellValue("lima") = "True" Then
Row.Item("empat") = False
Row.Item("tiga") = False
Row.Item("dua") = False
Row.Item("satu") = False
End If
'and so..on
ElseIf SelectedColumnName = "satu" Then
If DataGridView3.CurrentRowCellValue("satu") = "True" Then
Row.Item("lima") = False
Row.Item("empat") = False
Row.Item("tiga") = False
Row.Item("dua") = False
End If
End If
DataGridView3.CurrentCell = DataGridView3(e.ColumnIndex, e.RowIndex)
End If
End If
End Sub
And this is the functions for CurrentCell and CurrentRowCellValue in module
<System.Diagnostics.DebuggerStepThrough()> _
<Runtime.CompilerServices.Extension()> _
Function CurrentRowCellValue(ByVal sender As DataGridView, ByVal ColumnName As String) As String
Dim Result As String = ""
If Not sender.Rows(sender.CurrentRow.Index).Cells(ColumnName).Value Is Nothing Then
Result = sender.Rows(sender.CurrentRow.Index).Cells(ColumnName).Value.ToString
End If
Return Result
End Function
<System.Diagnostics.DebuggerStepThrough()> _
<Runtime.CompilerServices.Extension()> _
Function CurrentCellValue(ByVal sender As DataGridView) As DataGridViewCell
Return sender(sender.Columns(sender.CurrentCell.ColumnIndex).Index, sender.CurrentRow.Index)
End Function
and this is from CurrentCellDirtyStateChanged event
Private Sub DataGridView3_CurrentCellDirtyStateChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView3.CurrentCellDirtyStateChanged
If TypeOf DataGridView3.CurrentCell Is DataGridViewCheckBoxCell Then
DataGridView3.CommitEdit(DataGridViewDataErrorContexts.Commit)
End If
End Sub
I already set the DataGridView's ReadOnly property to False. The problem is that I still can check all the checkboxes in the same row.
Can someone give advice of what I did wrong here ?
Thanks
Some tips:
See this link concerning CellValuechanged event when working with checkBoxs
If they are unbound columns, you can't change values via the DataSource.Current row: table has no definition for lima, empat, ...
This workaround (using CellContentClick) works for me (no need to extension methods and CurrentCellDirtyStateChanged event):
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView3.CellContentClick
Dim checkboxIndexes As New List(Of Integer)
checkboxIndexes.Add(DataGridView3.Columns("lima").Index)
checkboxIndexes.Add(DataGridView3.Columns("empat").Index)
checkboxIndexes.Add(DataGridView3.Columns("tiga").Index)
checkboxIndexes.Add(DataGridView3.Columns("dua").Index)
checkboxIndexes.Add(DataGridView3.Columns("satu").Index)
If checkboxIndexes.Contains(e.ColumnIndex) Then
'check for false value because event occurs before row is validated
If DataGridView3.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = False Then
For Each index In checkboxIndexes
If index <> e.ColumnIndex Then
DataGridView3.Rows(e.RowIndex).Cells(index).Value = False
End If
Next
End If
End If
End Sub
I made an improve to the code added before in order to achieve my goals of checking checkboxes of the same row in different columns. It works for me.
Private Sub Grilla_CellClick(sender As Object, e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles Grilla.CellClick
Dim checkboxIndexes As New List(Of Integer)
checkboxIndexes.Add(Grilla.Columns("Select").Index)
checkboxIndexes.Add(Grilla.Columns("Select1").Index)
If checkboxIndexes.Contains(e.ColumnIndex) Then
'check for false value because event occurs before row is validated
If Grilla.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = False Then
For Each index In checkboxIndexes
If index <> e.ColumnIndex Then
'Do nothing here
Else
If Grilla.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = False Then
Grilla.Rows(e.RowIndex).Cells(index).Value = True
Else
Grilla.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = False
End If
End If
Next
Else
If Grilla.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = True Then
For Each index In checkboxIndexes
If index <> e.ColumnIndex Then
'Do nothing here
Else
If Grilla.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = False Then
Grilla.Rows(e.RowIndex).Cells(index).Value = True
Else
Grilla.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = False
End If
End If
Next
End If
End If
End If
Grilla.TableElement.Update(GridUINotifyAction.DataChanged)
End Sub

How to capture arrow keys in datagridview cell end edit in VB.net

Here is my code for Cell End Edit and Selection Changed event:
Private Sub dvJOBranch_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dvJOBranch.CellEndEdit
'get the current column and row index
curCol = e.ColumnIndex
curRow = e.RowIndex
'if the cell is blank, set it to zero
If IsDBNull(dvJOBranch.Rows(curRow).Cells.Item(curCol).Value) Then
dvJOBranch.Rows(curRow).Cells.Item(curCol).Value = 0
'convert it to integer
Else
dvJOBranch.Rows(curRow).Cells.Item(curCol).Value = _
Convert.ToInt32(dvJOBranch.Rows(curRow).Cells.Item(curCol).Value.ToString())
End If
'if the user do mouseclick in datagridview
isMouseClick = dvJOBranch.Capture.ToString()
'if the user does not click any cell from the datagridview
If isMouseClick = False Then
isEdited = True
iColumnindex = e.ColumnIndex
irowindex = e.RowIndex
If dvJOBranch.CurrentRow.Index = dvJOBranch.RowCount - 1 Then
If dvJOBranch.CurrentCell.ColumnIndex < dvJOBranch.ColumnCount - 1 Then
dvJOBranch.CurrentCell = dvJOBranch.Item(iColumnindex + 1, irowindex)
End If
isEdited = False
End If
End If
End Sub
Private Sub dvJOBranch_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dvJOBranch.SelectionChanged
'if the user does not click any cell from the datagridview
If isMouseClick = False Then
If isEdited Then
If dvJOBranch.CurrentCell.ColumnIndex < dvJOBranch.ColumnCount - 1 Then
dvJOBranch.CurrentCell = dvJOBranch.Item(iColumnindex + 1, irowindex)
Else
dvJOBranch.CurrentCell = dvJOBranch.Item(2, irowindex + 1)
End If
isEdited = False
End If
End If
'set it to false
isMouseClick = False
End Sub
The function of this code is to move the current cell to the right after editing using ENTER key, In my code I also capture the mouse click if the user click any cell because it has errors If i do not capture the mouse click, What I'm trying to do now is to capture the Arrow keys while I'm editing. Because after editing a cell, for example when I press Arrow key UP, it moves to the right like the Function for my ENTER key instead of moving upward.
Any help and guide will be appreciated, Thank you
You could be using the KeyUp event of the datagridview like this :
Private Sub dvJOBranch(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles dvJOBranch.KeyUp
If e.KeyCode = Keys.Up Then
' Do your code here
End If
End Sub
And if you want the enter key to be handled in there you could just use a select case also :
Private Sub dvJOBranch(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles dvJOBranch.KeyUp
Select Case e.KeyCode
Case Keys.Enter
' Code for enter
Case Keys.Up
' Code for up arrow
'Etc
End Select
End Sub

VB.NET Textbox KeyDown Event Not Firing

So,
I have a textbox on a tabcontrol page, and when someone tabs out of the textbox, it is suppose to move to the next tab. This was working great before I switched the form from a UserControl to an actual Form. This change did not change actual code.
So now, I have tried everything. I have the textbox to set to AcceptTab = True, and I have KeyPreview = False (because if the form grabs the event before the textbox does, it would mess things up I am assuming).
Here is my code for the textbox:
Private Sub txtMsgDTG_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles txtMsgDTG.KeyDown
'check for tabbed out
If e.KeyCode = Keys.Tab Then
'If the user tabs into this field after filling out the necessary fields ...
If txtMsgDTG.Text = String.Empty Then
'If the user left the field BLANK ...
'Move to next page:
TabControl1.TabPages(0).Enabled = True
TabControl1.TabPages(1).Enabled = True
TabControl1.TabPages(2).Enabled = False
TabControl1.TabPages(3).Enabled = False
TabControl1.TabPages(4).Enabled = False
TabControl1.SelectedIndex = 1
Else
'If the user did NOT leave the field blank ...
'validate message DTG
Dim dtgCheck As String
dtgCheck = ValidateDTG(txtMsgDTG.Text)
If dtgCheck <> "valid" Then
MsgBox(dtgCheck)
Else
'Move to next page:
TabControl1.TabPages(0).Enabled = True
TabControl1.TabPages(1).Enabled = True
TabControl1.TabPages(2).Enabled = False
TabControl1.TabPages(3).Enabled = False
TabControl1.TabPages(4).Enabled = False
TabControl1.SelectedIndex = 1
End If
End If
End If
End Sub
Any ideas guys?
The quick fix:
txtMsgDTG.Multiline = True
The other fix where you can keep Multiline = False is to subscribe to the TextBox's PreviewKeyDown event:
Private Sub txtMsgDTG_PreviewKeyDown(ByVal sender As Object, ByVal e As PreviewKeyDownEventArgs) Handles txtMsgDTG.PreviewKeyDown
If e.KeyCode = Keys.Tab Then
e.IsInputKey = True
End If
End Sub