Loading controls in Datagrid

H

Harish

Dear All,

I am being assigned a task of developing a .NET web application from
an existing client server(CS) application (VB). It is a requirement
that much of the things should look similar to the existing CS
Application. Now i have flexgrid in one of the form where there are
controls in the cell and the user can enter the information row wise
and then on close of the form the data is saved. And one more
requirement to load the grid with a single editable row(some of the
cells may be list boxes, some may be calendar control) and then save
the information to the DB. I know that we can use itemtemplate to
place the controls in the datagrid but needs more clarrification on
this.

I wanted to check if all these things are possible using a datagrid

Thanks in advance

Harish M.R
 
M

Mikael Gustavsson

Hi Harish!

Create a datagrid with one or more template columns (At least if you wish to
show dropdown lists and such)
Edit the template column. In the Item Template you add controls that will
show the information to the user.
In the Edit Item Template you add controls that allows the user to change
the data.

To allow the user to edit the data you need to set the EditItemIndex of the
datagrid. When you do this the row corresponding to the index will change
into editmode.

You can add a specific Edit, Update, Cancel column to the datagrid. When
using this type of column the datagrid fires the following events
(DataGrid dg)
dg.EditCommand : Is fired when the user presses a button with the
commandname Edit
dg.UpdateCommand : Is fired when the user presses a button with the
commandname Update
dg.CancelCommand : Is fired when the user presses a button with the
commandname Cancel

When the datagrid fires the EditCommand event you need to set the datagrids
EditItemIndex to the same index
as the button that was pressed.

private void dg_EditCommand(object sender, DataGridCommandEventArgs e)
{
dg.EditItemIndex = e.Item.ItemIndex;
UpdateDataGridData();
}

When the datagrid has finnished editing (After pressing either Update or
Cancel the corresponding event is fired)
In both these you need to tell the datagrid that the EditItemIndex is -1
(nothing is being edited)

You need to save the data while being edited. Personally I use home made
data carrying classes that I add to an ArrayList. But you could just as well
use a DataTable or a DataSet. Just update the data in the
dataset/datatable/customdatacarrier and bind it to the datagrid again to
update the changes made. Then when the user presses ok just take the
datacarrier and save it to the db.

Well, I hope this will give you some ideas at least. Good luck

//Mikael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top