dear i am in trouble
i am having a datagrid view where the name of Dgview and textbox name is textbox1
i want to search data according to textbox i want to write a code in events textbox1_keypress whenever you write a word L in textbox so the dgview row select the row where the row starts with L and after that i press I so the select dgview row whrer the dgview row starts with LI please help me on dis problem

note: datagridview already contain a databse table data in three field ProductId,ProductName,Company
Visual Studio 2008

Recommended Answers

All 4 Replies

You can cicle by the datagrid rows. On each row, compare if the left part of the first column text contents the search string in hte textbox. If found, then select the current row and exit.

For Row As Integer = 0 To Dgview.Rows.Count
	If Dgview.Rows(Row).Cells(0).Value.ToString.Substring(0, textbox1.Text.Length) = textbox1.Text Then
		Dgview.Rows(Row).Selected = True
		Exit For
	End If
Next

Hope this helps

Thanks Sir

sir tellme
i am having a form form1 and datagrid and textbox
form1 load
if i press a character or numeric data
datagrid row select who similar data with textbox
now we required coding if i press up/down arrow key so the focus move on datagrid row and datagrid current select row moves up and down

'
		'	Assuming the key pressed is stored in 
		'
		Dim KeyPressed As Keys
		'
		'	If there is any selecte row
		'
		If Dgview.SelectedRows.Count > 0 Then
			'
			'	Get it
			'
			Dim SelectedRow As DataGridViewRow = Dgview.SelectedRows(0)
			'
			'	And unselect
			'
			SelectedRow.Selected = False
			'
			'	Depending on the key pressed
			'
			If KeyPressed = Keys.Up Then
				'
				'	If up and the selected row is not the first
				'
				If SelectedRow.Index > 0 Then
					'
					'	Select the previous one
					'
					Dgview.Rows(SelectedRow.Index - 1).Selected = True
				End If
			ElseIf KeyPressed = Keys.Down Then
				'
				'	if down and and the selected row is not the last
				'
				If SelectedRow.Index < Dgview.Rows.Count - 1 Then
					'
					'	Select the next one
					'
					Dgview.Rows(SelectedRow.Index + 1).Selected = True
				End If
			End If
		End If

Hope this helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.