Reputation: 4978
Hi I have a C# windows forms DataGrid
in my Windows CE application.
The problem is when I bind the Data to the grid it shows an empty row at the bottom of the grid. AS below
I've read many answers about this and all of them were related to the DataGridView
. And also in WPF it says to set the following attribute
CanUserAddRows="false"
And Also they said to change the property
AllowUserToAddRows = false;
But there is no property available like this.. I'm using Visual Studio 2008
This is how I populate the grid
DataTable dtAddedItems = new DataTable();
DataColumn column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.AutoIncrement = true;
column.AutoIncrementSeed = 1;
column.AutoIncrementStep = 1;
dtAddedItems.Columns.Add(column);
dtAddedItems.Columns.Add("ItemHeadId");
dtAddedItems.Columns.Add("ItemName");
dtAddedItems.Columns.Add("IssuedQty");
dtgItems.DataSource = dtAddedItems;
How can I do this?
Upvotes: 1
Views: 900
Reputation: 9365
In winforms its: AllowUserToAddRows = false;
EDIT After your edit and comment
It's a DataGrid
so from MSDN
You can create a grid that enables users to edit data but prevents them from adding new rows by using a
DataView
as the data source and setting theAllowNew
property to false.
So with your code it should be:
DataTable dtAddedItems = new DataTable();
DataColumn column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.AutoIncrement = true;
column.AutoIncrementSeed = 1;
column.AutoIncrementStep = 1;
dtAddedItems.Columns.Add(column);
dtAddedItems.Columns.Add("ItemHeadId");
dtAddedItems.Columns.Add("ItemName");
dtAddedItems.Columns.Add("IssuedQty");
DataView dv = dtAddedItems.DefaultView;
dv.AllowNew=false;
dtgItems.DataSource = dv;
Upvotes: 1