Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Can someone guide me to an example for setting the row of a DataGridView programmatically? For Examle:

 

DataGridView1.row=12

 

I tried:

 

DataGridView1.Rows(yyy).Selected = True

 

but that only highlights the row.

Go Beavs!!!
Posted

DataGridView1.Rows(12).Selected = True

should do it

Make sure to Set SelectionMode = FullRowSelect

 

 

 

 

Can someone guide me to an example for setting the row of a DataGridView programmatically? For Examle:

 

DataGridView1.row=12

 

I tried:

 

DataGridView1.Rows(yyy).Selected = True

 

but that only highlights the row.

Currently Using: Visual Basic.Net 2005, .Net Framework 2.0
Posted

Ah ok then you want to EDIT that cell , i think.

 

.BeginEdit() should do it .. just make sure you have already selected it

 

its funny you ask this, i just figured this out a few days ago. Also, it's important to make sure you have only 1 cell selected. Oddly, I had to use .MultiSelect = False before I used .BeginEdit().

.ClearSelection() didnt seem to clear the selections alone, oddly.

 

so i did

       dgrid1.SelectionMode = DataGridViewSelectionMode.CellSelect
       dgrid1.MultiSelect = False
       dgrid1.ClearSelection()
       dgrid1.Item(column, row).Selected = True
       dgrid1.Item(colum, row).ReadOnly = False
       dgrid1.BeginEdit(False)

some of that is probably unnecessary

 

 

 

ALl that does is highlights the cell' date=' it does not change the focus to that row[/quote']
Currently Using: Visual Basic.Net 2005, .Net Framework 2.0
Posted

No, but I figured it out myself.

 

You must:

 

On form load

Dim bs As New BindingSource
Dim cmd As SqlCommand
Dim da As SqlDataAdapter
Dim ds As DataSet

da = New SqlDataAdapter(cmd)
       ds = New DataSet
       da.Fill(ds)
       bs.DataSource = ds
       bs.DataMember = ds.Tables(0).TableName

Dim dv As DataGridView = DataGridView1

       dv.DataSource = bs

 

trigger the change of selected records

 

Dim yyy = 22 'or any other desired row
DataGridView1.Rows(yyy).Selected = True
DataGridView1.FirstDisplayedScrollingRowIndex = yyy
bs.Position = yyy

Go Beavs!!!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...