Метод Path.of()
, добавленный в JDK 11, требует URI
в качестве параметра, а не String
. Например,
Scanner input = new Scanner(Path.of(new URI("file:///D:/test.txt")), StandardCharsets.UTF_8);
Или вы можете просто использовать new Scanner(File)
, как сказал другой ответ.
Может быть проблема в кейсе, значение в ячейках ["Имя"] начинается с заглавной буквы? Попробуйте использовать ToUpper или ToLower на обоих; или вы можете попробовать StartsWith (e.KeyChar, true) игнорироватьCase. Если вы пытаетесь выбрать строку, вам нужно сделать dataGridView1.Rows [i] .Selected = true
if (Char.IsLetterOrDigit(e.KeyChar))
{
foreach (DataGridViewRow dgvRow in myDgv.Rows)
{
if (dgvRow.Cells["ColumnName"].FormattedValue
.ToString().StartsWith(e.KeyChar.ToString(), true, CultureInfo.InvariantCulture))
{
dgvRow.Selected = true;
break;
}
}
}
Если DGV настроен для разрешения множественного выбора, то вам, очевидно, нужно отменить выбор любого существующего выбора.
This is a VS2008 VB.NET DataGridView extension meant to do kind of what you are doing but using a TextBox for searching information (not designed with case in mind but could easily be added). This extension works so perhaps there is something that might be helpful. I did notice that your code selects a row using select where mine uses CurrentCell.
<Runtime.CompilerServices.Extension()> _
Public Function PartSeek(ByVal GridView As DataGridView, ByVal ColumnName As String, ByVal Value As String, ByVal Part As Boolean) As Boolean
Dim Located As Boolean = False
If GridView.Columns.Contains(ColumnName) Then
Dim SingleRow As DataGridViewRow
If Part Then
SingleRow = (From Rows In GridView.Rows.Cast(Of DataGridViewRow)() _
Where Rows.Cells(ColumnName).Value.ToString().Contains(Value)).FirstOrDefault
Else
SingleRow = (From Rows In GridView.Rows.Cast(Of DataGridViewRow)() _
Where Rows.Cells(ColumnName).Value.ToString() = Value).FirstOrDefault
End If
If Not IsNothing(SingleRow) Then
If GridView.CurrentCell.RowIndex <> SingleRow.Index Then
GridView.CurrentCell = GridView(0, SingleRow.Index)
End If
DirectCast(GridView.Parent, Form).ActiveControl = GridView
Located = True
End If
Return Located
Else
Throw New Exception("Column '" & ColumnName & "' not contained in this DataGridView")
End If
End Function