Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid appears already in EditMode

Status
Not open for further replies.

Alcar

Programmer
Sep 10, 2001
595
US
Prolog: my colleagues already determined that I have lost connection with the real world today

given THAT, I believe I totally forgot how to make my datagrid appear ALREADY in edit mode on a given EditItemIndex.
Considering that the DataSet I bind to it has 1 row:

dgOrders.DataSource = ds.Tables[0];
dgOrders.SelectedIndex = dgOrders.Items[0].ItemIndex;
dgOrders.DataBind();

I get a nice OutOfRangeException on the second row...

any ideas?

loads of thanks! Daren J. Lahey
Just another computer guy...
If you are unsure of forum etiquette check here FAQ796-2540
 
dgOrders.DataBind()
dgOrders.edititemindex = yourIndexOfChoice
penny1.gif
penny1.gif
 
err....

switch those two statements.... one before the other
penny1.gif
penny1.gif
 
being an order entry form I would always like the last index to be opened in edit(unless the user is editing another row).
The problem appears when the order form is empty, I add an empty row to the DataSet and bind it to the datagrid:


ds = new dsOrders();
DataRow dr = ds.Tables[0].NewRow();
dr["StockNumber"] = "";
dr["ProductName"] = "";
dr["Quantity"] = 0;
dr["PricePerUnit"] = 0;
dr["ActualPrice"] = 0;
dr["Weight"] = 0;
dr["subtotal"] = 0;
ds.Tables[0].Rows.Add(dr);
ds.Tables[0].AcceptChanges();
ds.AcceptChanges();

dgOrders.DataSource = ds.Tables[0];
dgOrders.DataBind();

if I don't bind it once before and I try to open the first index in edit it gives me an OutOfRangeException error, therefore I do:


dgOrders.DataSource = ds.Tables[0];
dgOrders.DataBind();
dgOrders.EditItemIndex = 0;
dgOrders.DataBind();


but with this, my dgOrers_ItemCreated event doesn't get fired, for some strange reason. If I take the last two lines away, the event triggers fine.

mumble mumble Daren J. Lahey
Just another computer guy...
If you are unsure of forum etiquette check here FAQ796-2540
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top