Numeric Automatic

I want to fill column in datagrid with id and want it fill automatic when the row focus

so that i wrote this code and it'snot correct

i want any one correct it

Dim i As Integer

For i = 0 To i Step +1

Coming_tblDataGridView.CurrentRow.Cells(1).Value = Now

Coming_tblDataGridView.CurrentRow.Cells(2).Value = i

Next

Catch ex As Exception

End Try




Answer this question

Numeric Automatic

  • JuanMi

    Datagridviews are normally bound to a datasource (such as a datatable).

    If your database table is auto incrementing ID field then then if you used the wizards to set up the datasource and datagridview for the form then the typed dataset will have an auto incrementing field as well.

    If you are not using databinding or have chosen to do this manually then you will need a datasource. In this example I create a datatable and bind to it manually - so I dont have any database connection. I simply enter the rowcount +1 for the ID field but you could search for a max value - or keep an external counter in another table.

    Either way you'll need to be more specific about what your trying to do to get a definative answer .

    Public Class Form1
    Dim DT As New DataTable

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    '//Simply add a new row with a new value
    Dim icount As Integer = DT.Rows.Count
    DT.Rows.Add(icount + 1, "")

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    DT.Columns.Add("ID")
    DT.Columns.Add("Description")

    DT.Rows.Add(1, "Items1")
    DT.Rows.Add(2, "Items1")
    DT.Rows.Add(3, "Items1")

    '//Bind to a dataset
    DataGridView1.DataSource = DT
    DataGridView1.Columns(0).DataPropertyName = "ID"
    DataGridView1.Columns(1).DataPropertyName = "Description"
    End Sub
    End Class


  • Ricardo___

    I don't use datagridview that much, but your for/next is going nowhere. 0 to i = 0 to 0

  • Numeric Automatic