kcwallace Posted September 12, 2006 Posted September 12, 2006 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. Quote Go Beavs!!!
NeuralJack Posted September 12, 2006 Posted September 12, 2006 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. Quote Currently Using: Visual Basic.Net 2005, .Net Framework 2.0
kcwallace Posted September 12, 2006 Author Posted September 12, 2006 ALl that does is highlights the cell, it does not change the focus to that row Quote Go Beavs!!!
NeuralJack Posted September 12, 2006 Posted September 12, 2006 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'] Quote Currently Using: Visual Basic.Net 2005, .Net Framework 2.0
kcwallace Posted September 12, 2006 Author Posted September 12, 2006 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 Quote Go Beavs!!!
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.