Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.
For Each row As DataGridViewRow In Me.DataGridView1.Rows
If Not row.IsNewRow Then
row.Cells(0).Value = "1"
End If
Next
' Where "1" is the name of the item to select
Private Sub DataGridView1_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles DataGridView1.DataError
If e.Context = DataGridViewDataErrorContexts.Formatting Or e.Context = DataGridViewDataErrorContexts.PreferredSize Then
e.ThrowException = False
End If
End Sub
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Creates a datatable
Dim dt As New DataTable
dt.Columns.Add("id", GetType(Integer)).AutoIncrement = True
dt.Columns.Add("item", GetType(String))
' Adds some values
For x As Int16 = 0 To 10
Dim dr As DataRow = dt.NewRow
dr("item") = "Item " & x.ToString
dt.Rows.Add(dr)
Next
' Create a new combo and adds it to the grid
Dim combo As New DataGridViewComboBoxColumn
combo.DataSource = dt.DefaultView
combo.DisplayMember = "item"
combo.ValueMember = "id"
Me.DataGridView1.Columns.Add(combo)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For Each row As DataGridViewRow In Me.DataGridView1.Rows
row.Cells(0).Value = "Item 3"
Next
End Sub
Private Sub DataGridView1_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles DataGridView1.DataError
If e.Context = DataGridViewDataErrorContexts.Formatting Or e.Context = DataGridViewDataErrorContexts.PreferredSize Then
e.ThrowException = False
End If
End Sub
End Class
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Try to change to :
Open in new window