.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Post New Web Links

how to update cell in datagridview ?

Posted By:      Posted Date: October 27, 2010    Points: 0   Category :Windows Application


i have datagridview that connect to my database (access)

if i stay on any cell and change the value, a see that the value is changed

but when i make refresh i see that the value is back to the original value.

how i can update this cell (without sql query)

i bind dataset to datagridview like this:

dsView = new DataSet();
= new OleDbDataAdapter("SELECT * FROM Items", Conn);
.Fill(dsView, "Items");

View Complete Post

More Related Resource Links

I need to set the value of a gridview cell during update.

Hi,  I've been reading the posts here and I'm not finding, or maybe just not understanding, the answer I need so here's my problem. I have a small gridview and the update works very well. The issue is I need to have one of the fields set to a value from my code either when the record is open for undating or when the update runs.  Here is my gridview and the datasource info:<asp:GridView ID="GridViewItemLog" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" CellPadding="3" DataKeyNames="LogID" DataSourceID="SqlDataSourceItemLogEntries" GridLines="Vertical" onrowdatabound="GridViewItemLog_RowDataBound" onrowupdating="GridViewItemLog_RowUpdating" onrowediting="GridViewItemLog_RowEditing"><AlternatingRowStyle BackColor="Gainsboro" /><Columns><asp:CommandField ButtonType="Image" CancelImageUrl="~/Resources/StopSmall.png" EditImageUrl="~/Resources/EditSmall.png" ShowEditButton="True" UpdateImageUrl="~/Resources/Save.png" /><asp:Boun

How to update single cell of excel sheet using oledb connection,

 Friends i got some codes from net  by using that i can update a excel sheet ,but there we have to specify some header fields name in command string like as fallows ,Update [Sheet1$] set ProductName="IBG" where ProductId=5but i want to update a single cell of excel sheet only,let say O12 cell i want to change somedata,how it is possible that i don't know.plz help me out... thanks in advance...  

How to make a DataGridView Cell/Column not enterable / selecatble

Hi, I am trying to make a Column in a DataGridView non-entaerable (the user should not be able to set focus to the cell neither using the mouse nor the keyboard). I already tried to change the CurrentCell property in the CellStateChanged. But in this event-handler the CurrenCell is the "old" one; setting it to any value doesn't help, because the value is set after calling this procedure. In Delphi there is an event-handler for entering a cell, where you can tell whether the user is allowed to enter a cell. Is there anything comparable in C#? Any other suggestions?

Improving performance of UPDATE CUBE by executing preceding CREATE CACHE for the same cell / subcube

Hi All, Recently I came across one of suggestions by Microsoft Advisory consultant regarding optimization data write-back pattern for the SSAS cubes. It was recommended issuing CREATE CACHE command following by UPDATE CUBE for the same cell/subcube definition: CREATE CACHE FOR [MYCUBE] AS ("Cross join of all the dimension members defining subcube to be updated") UPDATE CUBE [MYCUBE] SET ("Cell") = 100, ("Another Cell") = 200,... etc. for every cell. This seems quite weird, but based on our benchmark the entire process (CREATE CACHE and UPDATE CUBE) takes less time than just UPDATE CACHE. Folks, can someone advice on the insights of the process? Shell this approach to be suggested for an enterprise-level planning application? Regards, -h

datagridview select cell


okay, this is driving me crazy!!!

In my datagridview, on the current row, how do I select/set the focus of a particular cell?  I am already on the row I just want to set the focus to the third cell.


after I validate a cetain cell, I want to tab to the next cell

I tried:


SendKeys.Send("{TAB}")  and the application stalls


I tried:


DgvSched.CurrentCell = DgvSched[3, DgvSched.CurrentRow.Index];

and also

DgvSched.CurrentCell = DgvSched[3, e.RowIndex];

and I get the following error:

An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll


when I remove the above statement the error does not come up.




Find out if DatagridView Cell is Clicked


I have 2 grids on a form.

Both grids are binded to object Panel and PanelLines.

If user click first panel grid, the second panel line grid will show the related panel lines.

If the user clicks the panel grid on the same cell again, I want panel line grid to scroll rows as such visible rows hide and bottom rows show up.

The following code does the scrolling part.

dgvPanelItem.FirstDisplayedScrollingRowIndex = dgvPanelItem.DisplayedRowCount(False) - 1
But I need help in finding out, if first grid ( panel grid ) is already clicked or not.

Find out if DatagridView Cell is Clicked


I have 2 grids on a form.

Both grids are binded to object Panel and PanelLines.

If user click first panel grid, the second panel line grid will show the related panel lines.

If the user clicks the panel grid on the same cell again, I want panel line grid to scroll rows as such visible rows hide and bottom rows show up.

The following code does the scrolling part.

dgvPanelItem.FirstDisplayedScrollingRowIndex = dgvPanelItem.DisplayedRowCount(False) - 1
But I need help in finding out, if first grid ( panel grid ) is already clicked or not.

Painting/Filling a specific cell using CellPainting event of datagridview



I am trying to paint a quantity column in data grid with color red, however when I do so cell alignment changes to left. 

Seems like I have to convert e.value to string in order for this to work and when I do that the cell alignment changes.

Quantity column is of type decimal.

Also I would appreciate if you can guide on how i can fill the certain columns in data grid with certain color(for ex. yellow).

 if (this.dtaGridView.Columns[7].Index ==e.ColumnIndex && e.RowIndex >= 0)




handle up & down keys while editing a cell in datagridview to affect listbox


I have a datagridview. i have overridden some datagridview methods to capture enter key and updown key in a separate class



i also have a listbox. while i am editing a cell the listbox is being visible and searching in the listbox for what is in the cell's textbox. (i am also able to catch the up down key but from a different class which overrides some methods.)

Now what i need is when i press up and down key the listbox's selected items will change accordingly.

Plz help me to solve it.

DataGridView & Custom cell painting


I'm creating a schedule using a datagridview.  The cells in the grid need a lot of special behavour so I created my own Column and Cell classes.  In the Cell.Paint method I draw the cell text in various colors, draw images and lines, depending on data values.

My question is this:  What is the correct order to draw parts of the cell using the DataGridViewPaintParts?  Does it matter?  At present, the display is horrid - sometimes the cells are transparent (I can see what's underneath the application) and the text is scrambled.  A really good example of how to paint a cell would be great!


C# Datagridview cell text compare



I have 2 datagridviews on a form and would like to know if it is possible to compare the text in the 2 views and highlight any differences?

For example:

DG1: Cell A1 Text > This is a test

DG2: Cell A1 Text > This iss some test

Is it therefore possible to highlight "iss" , "some" in red and show the corresponding dgv1 text in green?

I have done this with 2 richtextboxes and cannot work out how to do this with datagridview?

Any help with this is most welcome

Thanks in advance

DataGridView Combo Box Cell with sub menu


I need to create a column in the datagirdview that functions like a combo box with sub menus. As an example we have a cell that contains modes of transportation, and rather then a single list to select from the user can choose cars and then get a sub menu of car types or they can choose trucks and get a sub menu of trucks to choose from. 

Modes of Transportation
cars -> Volkswagon Rabbit, Volkwagon Dasher, Volkswagon Bug
truck -> Ford F150, Toyota etc . . 

I hope I have explained my problem accurately enough, if anyone has any insights or suggestions I would love to hear them.




enabling the cursor in a specific cell within a datagridview


guys, i have an add record button in my datagridview application

i would like to enable the cursor on the first cell (in the last row) so the user would be able to enter some more information

i created an on click event, and can get and select the last row

but how do i set the cursor inside the specific cell ?

  Private Sub TestButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TestButton.Click
        Dim RowCount As Integer = Me.grdAccountTypes.RowCount - 1
        Me.grdAccountTypes.FirstDisplayedScrollingRowIndex = RowCount
        Me.grdAccountTypes.CurrentCell = grdAccountTypes.Rows(RowCount).Cells(0)
End SUb

Presenting Data with the DataGridView Control in .NET 2.0 > Defining Custom Column and Cell

in this link u can find the explanation about how to bind image column at run time.

Datagridview automatically update in c# by two Forms.


Hi to every body.

Note: I use Windows Application not Web Application.

 I am programming a database(Library database) program whit C# and SQL Server. I have a Tabel suppose that tblBook that show the information about my library books. I have a MainForm that have a Datagridview that linked to my tblBook and show my Books information that inserted in tblBook. in Main Form I have a Button that open another Form(Name is frmNewBook) for inserting information about a new Book in my tblBook. when I open frmNewBook by that Button and insert a new record at this time I want the Main Form automaticaly Update and the Datagridview show also new record information automaticaly by closing the frmNewBook Form or by Pushing the button(Save New Record.) that's my question.

 thank a lot Saeed.



c# 2008 Datagridview numericupdown cell not working properly. Odd layout behaviour


Hi all,

Francesco from Italy here, working with MS products since I was professionally born... that's like a century ago or something like that!

This is my 1st post in MSDN forums, so I hope it would be well accepted :)


I'm working with datagrdiview and custom numericupdown cell. I started from here


So, I downloaded the code attached there, opened the solution with Visual studio 2008, processed the automatic upgrade from 2005 to 2008 and started to play a bit with it.

It works pretty well, since I tried to use it the way you can see in this project


What do I do?

- I have a MDI form containing a simple child form 

- the child form has a splitcontainer, containing a treeview in the left panel

- the treeeview has 4 nodes and, clicking node 1 or 2, loads an usercontrol, containing datagridview with the custom numericoupdown object.

It looks great!

But... if you play a bit with the fields, you'll get an odd behaviour.

The first object I interact with works pretty well. The second object (hosted by the other usercontrol) has a funny behaviour... It simply doesn't work properly.

datagridview Cell Edit


Hi, I have one big problem.

i have one grid, with dynamic data, i need to make somes lines with ready only, and its ok works if i click with mouse and keyboard, but if i use the delete key, its possible to delete de cell content.

How to disable the key delete if my row or cell is ready only ?

Best Regards


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend