editing data in a datagrid

  • Thread starter tigerbalm via DotNetMonster.com
  • Start date
T

tigerbalm via DotNetMonster.com

Hallo!

I have filled a datagrid with data from a database. I would like to edit
the data in the datagrid and save it back to the database. My problem is
that I don't really know how to capture the event of the cell that I am
editing. The code below works but I would like to edit the data in a cell
and then for example click a button and save it.


Here is little of my code :

void Button5Click(object sender, System.EventArgs e)
{
int colNr = dataGrid4.CurrentCell.ColumnNumber;
int rowNr = dataGrid4.CurrentCell.RowNumber;
string s = dataGrid4.CurrentCell.ToString();
string currentCellData = null;
EventHandler eh = null;
currentCellData = textBox2.Text;
DataGridCell dc = new DataGridCell(rowNr, colNr);
dataGrid4[dc] = currentCellData;

}
 
C

ClayB [Syncfusion]

To get the value directly from the cell, try code like:

int colNr = dataGrid4.CurrentCell.ColumnNumber;
int rowNr = dataGrid4.CurrentCell.RowNumber;
object cellValue = dataGrid4[rowNr, colNr];

=================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools
 
D

Dhanushka Nuwan

Try This Out

dataGrid4.CurrentCellChanged += new EventHandler(Grid_CurCellChange);

private void Grid_CurCellChange(object sender, EventArgs e)
{
object currentCell = dataGrid4[dataGrid4.CurrentCell.RowNumber,
dataGrid4.CurrentCell.ColumnNumber]
}

Regards,
Dhanushka



ClayB said:
To get the value directly from the cell, try code like:

int colNr = dataGrid4.CurrentCell.ColumnNumber;
int rowNr = dataGrid4.CurrentCell.RowNumber;
object cellValue = dataGrid4[rowNr, colNr];

=================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools

message news:[email protected]...
Hallo!

I have filled a datagrid with data from a database. I would like to edit
the data in the datagrid and save it back to the database. My problem is
that I don't really know how to capture the event of the cell that I am
editing. The code below works but I would like to edit the data in a cell
and then for example click a button and save it.


Here is little of my code :

void Button5Click(object sender, System.EventArgs e)
{
int colNr = dataGrid4.CurrentCell.ColumnNumber;
int rowNr = dataGrid4.CurrentCell.RowNumber;
string s = dataGrid4.CurrentCell.ToString();
string currentCellData = null;
EventHandler eh = null;
currentCellData = textBox2.Text;
DataGridCell dc = new DataGridCell(rowNr, colNr);
dataGrid4[dc] = currentCellData;

}
 
T

tigerbalm via DotNetMonster.com

thanks guys, the code works. But I also want to send the updated data back
to the database. I programmed in Java before and there it was easy to
browse through the cells and send the updates back to the database. How do
I do it in C#? I know I have to use the dataadapters updatecommand. Please
tell me how to do it.
 

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

Top