I am developing a Windows mobile application. How can I show only two columns of the twelve in my datatable in the grid?.
Also, is it possible to delete rows in the Windows Mobile datagrid?
Please provide sample code.
Hi StartClass0830,
Thanks for your reply, i don't want remove the columns in my grid, Let's say In the windows mobile application the dtNewOrder table contains 11 columns i need to display the certain fields from dtNewOrder to the datagrid.
And another question is the datagrid contains 10 rows how i am deleting the certain rows in the grid.
Please give me sample code; I have been struggling with this problem for a couple of days.
Here is what I have:
Imports System.Data
Imports System.Text
Imports System.IO
Imports System.Data.SqlServerCe
Dim dtCustomerName As DataTable
Dim dtNewOrder As DataTable
Dim _objDataAccess As New DataAccess
Private Sub NewOrder_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dtNewOrder = CreateNewOrderDataTable()
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
AddNewOrderMember(dtNewOrder)
End Sub
Private Sub AddNewOrderMember(ByVal dtNewOrder As DataTable)
Try
Dim NewOrderMemberRow As DataRow = dtNewOrder.NewRow()
NewOrderMemberRow("OrderID") = System.Guid.NewGuid()
NewOrderMemberRow("SalesPersonID") = "123"
NewOrderMemberRow("CustomerGroupID") = ddlCutomerGroup.SelectedValue.ToString()
NewOrderMemberRow("CustomerID") = ddlCustomerName.SelectedValue.ToString()
NewOrderMemberRow("CustomerItemCode") = "123"
NewOrderMemberRow("Category") = "Dummy Category"
'NewOrderMemberRow("Description") = "Dummy Des"
NewOrderMemberRow("OrderUnit") = "Each"
NewOrderMemberRow("OrderQuantity") = txtOrderQuantity.Text
NewOrderMemberRow("UnitPrice") = "123"
NewOrderMemberRow("TotalAmount") = "30000"
dtNewOrder.Rows.Add(NewOrderMemberRow)
dtNewOrder.AcceptChanges()
If dtNewOrder.Rows.Count > 0 Then
dgNewOrder.DataSource = dtNewOrder
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Mobile Retail Merchandising", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
End Try
End Sub
Private Function CreateNewOrderDataTable() As DataTable
dtNewOrder = New DataTable("NewOrder")
Try
dtNewOrder.Columns.Add(New DataColumn("OrderID", Type.GetType("System.String")))
dtNewOrder.Columns.Add(New DataColumn("SalesPersonID", Type.GetType("System.String")))
dtNewOrder.Columns.Add(New DataColumn("CustomerGroupID", Type.GetType("System.String")))
dtNewOrder.Columns.Add(New DataColumn("CustomerID", Type.GetType("System.String")))
dtNewOrder.Columns.Add(New DataColumn("CustomerItemCode", Type.GetType("System.String")))
dtNewOrder.Columns.Add(New DataColumn("Category", Type.GetType("System.String")))
dtNewOrder.Columns.Add(New DataColumn("Description", Type.GetType("System.String")))
dtNewOrder.Columns.Add(New DataColumn("OrderUnit", Type.GetType("System.String")))
dtNewOrder.Columns.Add(New DataColumn("OrderQuantity", Type.GetType("System.String")))
dtNewOrder.Columns.Add(New DataColumn("UnitPrice", Type.GetType("System.String")))
dtNewOrder.Columns.Add(New DataColumn("TotalAmount", Type.GetType("System.String")))
Dim PrimaryKeyColumns() As DataColumn = New DataColumn(1) {}
PrimaryKeyColumns(0) = dtNewOrder.Columns("OrderID")
dtNewOrder.PrimaryKey = PrimaryKeyColumns
Return dtNewOrder
Catch ex As Exception
MessageBox.Show(ex.Message, "Mobile Retail Merchandising", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
Return dtNewOrder
End Try
End Function
Thanks brite