473,412 Members | 2,994 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

editing data in a datagrid

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;

}
Nov 17 '05 #1
3 1565
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

"tigerbalm via DotNetMonster.com" <fo***@nospam.DotNetMonster.com> wrote in
message news:79******************************@DotNetMonste r.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;

}

Nov 17 '05 #2
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 [Syncfusion]" <cl***@syncfusion.com> wrote in message
news:eP**************@TK2MSFTNGP10.phx.gbl...
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

"tigerbalm via DotNetMonster.com" <fo***@nospam.DotNetMonster.com> wrote in message news:79******************************@DotNetMonste r.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;

}


Nov 17 '05 #3
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.

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...sharp/200505/1
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Swaroop | last post by:
Hi, I am using a Datagrid to populate the details given by a user in the footer of the datagrid.i am using an object array to populate the datagrid(a sample project so not using a database to...
4
by: TT (Tom Tempelaere) | last post by:
Hi, Suppose there is a DataGrid on a form bound to a DataTable. When a user is editing a cell without leaving the cell, and then closes the form, the value is not updated to the underlying data...
0
by: Dave | last post by:
Tried posting in the Winform Forum without much luck, so posting here... After inserting a new data row to a DataTable that is bound to a datagrid, I am unable to change data in a row that is...
3
by: Islamegy | last post by:
When i press btn_save all changed rows in my grid get saved except the last editing row... I want my btn_Save to end editing in the datagrid.. so if user didn't press "enter" after editing last...
1
by: Blake Versiga | last post by:
When editing a datagrid (C#) I need to know if the user changed the value of cell AND what the previous value was. Is this possible? If so how do I get the previous value or at least if the...
0
by: Raterus | last post by:
Here is my only problem with using the datagrid to edit data. Say I have a moderate sized table, with about 15 columns. I want to allow a user to be able to edit most all of these fields, except...
9
by: tshad | last post by:
Is there a way to use your own image in place of the automatic one that ASP uses when doing editing in your DataGrid pages? We already have a style of button we are using and would like to be...
0
by: jason | last post by:
hi, I have a datagrid in my input form. Using datagrid inplace editing to save data (chinese characters) entered by user. It works as expected on my test record. But, when i started to...
0
by: prerak_v_shah | last post by:
Hi, Friends, I have been developing datagrid program in .Net 1.1 and having VB.Net as a programming language. I have created a datagrid which is bound to a datatable as its datasource. It also...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.