Hi all,
I need an editable datagrid with one row only. Means, if user enters one record in the datagrid, I dont want to add a new row in the data grid.
Thanks.
Printable View
Hi all,
I need an editable datagrid with one row only. Means, if user enters one record in the datagrid, I dont want to add a new row in the data grid.
Thanks.
There is property for allowing cells editing , I forgot what's called . If you're not so happy with the exist DataGrid , try the ones in CodeProject.com with more functions .
Would you please provide me link of that datagrid.
Do you mean an Unbounded DataGrid or do you mean you want to allow user to add new rows to existing data in the datagrid?Quote:
Originally Posted by usamaalam
If its the first case then all you need to do is create a DataTable an empty one and then bind to datasource to that DataTable.
I need an unbound editable datagrid with only one row. Means when user enters record in the first row, I dont want to add second row and restrict datagrid to be only for one record.
Here is an example, i have added an empty row and then disabled AllowNew property. You could also check the RowChanged event and disable it there if you need to allow n number of rows in future instead of one.Quote:
Originally Posted by usamaalam
Here is the code :
Code:
private void Form1_Load(object sender, System.EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Children Name", Type.GetType("System.String"));
dt.Columns.Add("Age", Type.GetType("System.Int32"));
dt.Columns.Add("Sex", Type.GetType("System.String"));
object [] d = {"",0,""};
dt.Rows.Add(d);
this.dataGrid1.DataSource = dt.DefaultView;
((DataView)this.dataGrid1.DataSource).AllowNew=false;
//dt.RowChanged+=new DataRowChangeEventHandler(dt_RowChanged);
}