How can I do it?

  • Thread starter Thread starter Chuen
  • Start date Start date
C

Chuen

Hi, all,

If I want to datagrid1 locate to row where dno="002",how can I do it?


Dim Conn As String = "Provider=vfpoledb;Data
Source=H:\BACKUP\NEWBACK1\RSKJGZ7\BACKNGX\DATA\gxrs.dbc"
Da = New OleDbDataAdapter("Select Dno,Dname From Department", Conn)
dt = New DataTable
Da.Fill(dt)
DataGrid1.DataSource=dt

Thanks in advance!

Chuen
 
If I want to datagrid1 locate to row where dno="002",how can I do it?

Apply a dataview. Or you can use the datatable's select method. Or you can
use the Find method (assuming dno is the PK).
 
Lucas,

As addition to Lucas, his answer and than: using the underlaying datasourcre
in your sample "dt".

Cor
 
Thanks for your response, in my example as following,

Dim Conn As String = "Provider=vfpoledb;Data
Source=H:\BACKUP\NEWBACK1\RSKJGZ7\BACKNGX\DATA\gxrs.dbc"
Da = New OleDbDataAdapter("Select Dno,Dname From Department", Conn)
dt = New DataTable
Da.Fill(dt)
DataGrid1.DataSource=dt

dt has totally 800 rows. I means, if I put a command button(Cation: Find)
and a textbox named DnoText in form(which datagrid1 locates), when I input
any value in textbox and then click such command button, the datagrid1 will
locate to the row whose dno is value input in DnoText.

Thanks and hope that you can give me any idea!

Chuen
 
Chueng,

Maybe, however tell first something more what you want to archieve, because
(not knowing how it is with others) for me that is not clear.

The simplest answer on your question had been by instance, go to your screen
take the mouse and click on that row. However I assume that is not what you
want.

Cor
 
Chuen,

The only simple idea I can come up is this.
(For this your datagrid should absolutly be set with sort off)

I hope this helps?

Cor
\\\ needs 1 datagrid 1 button and 1 textbox
Dim dt As New DataTable
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
dt.Columns.Add("datet", GetType(System.DateTime))
For i As Integer = 0 To 800
Dim dr As DataRow = dt.NewRow
dr(0) = Now.Date.AddDays(i)
dt.Rows.Add(dr)
Next
DataGrid1.DataSource = dt
DataGrid1.AllowSorting = False
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim mdt As Date = CDate(TextBox1.Text)
For I As Integer = 0 To 800
If DirectCast(dt.Rows(I)(0), Date) = mdt Then
DataGrid1.Select(I)
Exit Sub
End If
Next
End Sub
///
 
Back
Top