Datagrid -Last row always blank for add new record
-
Hello, i am beginner in vb.net. I know well how to bind the data in a datagrid.Now i want to add a new record in to a table through datagrid thats why in my datagrid last row is always blank. How it is possible? How to enter new record in a datagrid? Any one know the solution help me. aruljothi
-
Hello, i am beginner in vb.net. I know well how to bind the data in a datagrid.Now i want to add a new record in to a table through datagrid thats why in my datagrid last row is always blank. How it is possible? How to enter new record in a datagrid? Any one know the solution help me. aruljothi
what you need to do is add rows dynamically to the table source of the datagrid for eg:- you have a material table as a datasource to your datagrid.Now you dynamically add rows to this table.The rows added are material detail selected by user. the user selects specific material from the drop down combobox here is a sample code snippet Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click Dim drow As DataRow = material.NewRow Dim drv As DataRowView = CType(cmbmatnam.SelectedItem, DataRowView) Try drow("column1") = drv("mat_id") drow("Column2") = drv("mat_name") drow("Column3") = drv("Rate") drow("Column4") = drv("Quantity") drow("Column6") = "Enter Quantity" material.Rows.Add(drow) material.AcceptChanges() Catch ex1 As System.NullReferenceException MessageBox.Show("There are No Materials In this Category") Catch ex2 As System.Data.ConstraintException MessageBox.Show("Material Is already Selected") Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub I hope this helps Mandar Patankar Microsoft Certified professional