Home All Groups Group Topic Archive Search About

DataTable - set a specific row.

Author
22 May 2010 3:26 PM
Mr. X.
Hello.
How can I set a specific row of a dataTable ?
(I.e the DataTable has 10 rows, and I want to focus on row no. 7).

Thanks :)

Author
22 May 2010 4:43 PM
Onur_Güzel
On May 22, 6:26 pm, "Mr. X." <nospam@nospam_please.com> wrote:
> Hello.
> How can I set a specific row of a dataTable ?
> (I.e the DataTable has 10 rows, and I want to focus on row no. 7).
>
> Thanks :)

Assuming your DataTable is bounded to a DataGridView because of using
term "focus" which you may have meant it as "selecting"?

So, you can do:

' Drag and drop a datagridview and make sure it has one column at
least.
'-----------------------------------
Dim dt As New DataTable
' Adding 9 rows upon existing one, which will be 10 in total.
For x As Integer = 1 To 9

Dim drow As DataRow = dt.NewRow

            dt.Rows.Add(drow)
Next


DataGridView1.DataSource = dt

DataGridView1.Rows(0).Selected = False
DataGridView1.Rows(6).Selected = True
'-----------------------------------

HTH,

Onur Güzel
Author
22 May 2010 4:54 PM
Mr. X.
I forgive for now using bindingSource - it seems too complicated, because
there are many things I need to do manually.
There is no connection to bindingSource.
But, as it seems, DataTable is only a container.
To go to the current row, I need bindingSource
So I think I try using bindingSource as a solution, but not connect it
directly to dataGridView object.

Thanks :)

Show quoteHide quote
"Onur Güzel" <kimiraikkone***@gmail.com> wrote in message
news:0f498ee3-77f8-4ac8-8389-b73eaafc221e@c11g2000vbe.googlegroups.com...
> On May 22, 6:26 pm, "Mr. X." <nospam@nospam_please.com> wrote:
>> Hello.
>> How can I set a specific row of a dataTable ?
>> (I.e the DataTable has 10 rows, and I want to focus on row no. 7).
>>
>> Thanks :)
>
> Assuming your DataTable is bounded to a DataGridView because of using
> term "focus" which you may have meant it as "selecting"?
>
> So, you can do:
>
> ' Drag and drop a datagridview and make sure it has one column at
> least.
> '-----------------------------------
> Dim dt As New DataTable
> ' Adding 9 rows upon existing one, which will be 10 in total.
> For x As Integer = 1 To 9
>
> Dim drow As DataRow = dt.NewRow
>
>            dt.Rows.Add(drow)
> Next
>
>
> DataGridView1.DataSource = dt
>
> DataGridView1.Rows(0).Selected = False
> DataGridView1.Rows(6).Selected = True
> '-----------------------------------
>
> HTH,
>
> Onur Güzel
Author
22 May 2010 5:04 PM
Mr. X.
O.K.
My assumption works.
I am using BindingSource, but not connect it directly to dataGridView
object.
Now thing works fine ...

Anyway, Thanks :)