Solved

Edit datagrid

Posted on 2006-11-12
14
247 Views
Last Modified: 2010-04-23
Hi,

How can I update a datagrid? pls. give a vb sample.

ayha
0
Comment
Question by:ayha1999
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 7
14 Comments
 
LVL 34

Expert Comment

by:Sancler
ID: 17925267
What do you mean by "update a datagrid"?

A datagrid displays data which is held in its datasource - usually a datatable.  If the data in the datatable changes the display in the datagrid is automatically updated.  In that sense, you do not need to "update a datagrid".  If you want to change the data in the datatable you can do so by typing in the cells in the datagrid.  To that extent you "update a datagrid" by typing in it.

I think you need to say a bit more about what it is you are actually doing and trying to achieve.

Roger
0
 
LVL 7

Author Comment

by:ayha1999
ID: 17926105
Hi,

I want to change data in the cells and update the table with data validation. then update the datagrid with new data in the table.

ayha
0
 
LVL 34

Expert Comment

by:Sancler
ID: 17928951
Sorry.  This question is still too amorphous.

I see from

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_22017837.html

that you have already accepted an answer to a similar question.  So, in the light of that, what code have you currently got and what is wrong with it?

Roger
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 7

Author Comment

by:ayha1999
ID: 17930325
Hi,

I expected that the previously accepted includes everything I need related to datagrid but it doesn't, otherwise I would never have to ask this question again.  Most of the information in that is related to formting.

ayha
0
 
LVL 7

Author Comment

by:ayha1999
ID: 17946793
Hi,

how can I place 'Edit' button in each row in webform datagrid as in web datagrid?

ayha
0
 
LVL 34

Expert Comment

by:Sancler
ID: 17946974
Have a look at this.

http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q888q

But with a Winforms datagrid you don't need a button to edit it.  You just enter the cell, with the mouse or tabbing or keys, and type whatever new value you want.  Have you tried it?

Roger
0
 
LVL 7

Author Comment

by:ayha1999
ID: 17947068
Hi,

could u pls. tell me which question explains about editing in the above link?  when I type in the cell and press enter which event fires?
0
 
LVL 34

Expert Comment

by:Sancler
ID: 17951664
When you leave a cell - whether mouse or by tabbing, or use of the arrow keys, or by pressing Enter - the DataGrid's CurrentCellChanged event fires.

Roger
0
 
LVL 7

Author Comment

by:ayha1999
ID: 17974560
hi,

datagrid editting possible only by cell by cell update? how can I retrive value of current cell? suppose I have a row with partno , name, category ete.  

partno   name   category
A001    part 1    tools
A002    part 2    tools

here I am editing name of the second row then how can I retrive partno of that row and changed name of the cell?

ayha

0
 
LVL 34

Expert Comment

by:Sancler
ID: 17975224
>>
datagrid editting possible only by cell by cell update?
<<

Your question was "when I type in the cell and press enter which event fires".

The content of any cell can be read or set by the DataGrid's .Item property.  E.g.

   MyValue = MyDataDrid(thisRow,thisCol)

or

   MyDataDrid(thisRow,thisCol) = myValue

thisRow and thisCol are zero-based indexes.  So, from your example,

   myPartNo = MyDataGrid(1,0)

and

   myName = MyDataGrid(1,1)

I have to say, though, that your comments and questions still suggest to me that you may be misunderstanding the nature of a DataGrid in Windows Forms.  The datagrid is not something that, of itself, is "edited".  It is a mechanism for "editing" the datatable which is its datasource.  So, when you say "I am editing name of the second row then how can I retrive partno of that row and changed name of the cell", if you are editing the name on the second row in the datagrid what that means to me is that you are typing in different text in the name column in the second row of the datagrid so that it will be changed in the corresponding row and column in the datatable.  So far as I can see, doing that, you have no need to "retrieve partno of that row" - it is there in front of your eyes in the datagrid - or the "changed name of the cell" - that is also there in front of your eyes.  It will be reflected automatically in the datatable as soon as you navigate to another row in the datagrid or even before that if you force that to happen by calling

   BindingContext(myBoundDataTable).EndCurrentEdit

If, on the other hand, you want programmatically to change the name part2 to, for example, partB then you would normally do that in the datatable itself, and that change would then be reflected in what the datagrid shows.

I really think that, if you need any further clarification, you must post what code you've got and identify specifically what problems it is giving you and an which lines.

Roger
0
 
LVL 7

Author Comment

by:ayha1999
ID: 17975466
Hi Roger,

I have already mentioend that when I change text and press or lose focus of that cell then I want to update the table itself. I want to allow users to change the table through datagrid. is there any otehr way to do that?  I used datagrid1.UpdateCommand in web datagrid to do that where I can retrive each and every row details through findcontrol or any other method.

ayha
0
 
LVL 34

Expert Comment

by:Sancler
ID: 17976312
You say

>>
I have already mentioend that when I change text and press or lose focus of that cell then I want to update the table itself.
<<

I have already said that, once a new value has been typed in a datagrid cell

>>
It will be reflected automatically in the datatable as soon as you navigate to another row in the datagrid or even before that if you force that to happen by calling

   BindingContext(myBoundDataTable).EndCurrentEdit
<<

Have you tried that?  If so, what is your problem with it?

Forget the web datagrid.  Although I do not do web stuff myself, my understanding is that it is a completely different animal and works in completely different ways.

What you need to do is create a Windows Forms project, fill a datatable, bind it to a datagrid and actually try to do things with it.  Here's an example

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbwlkwalkthroughdisplayingdatafromsingletableinwindowsform.asp

Until you've actually done that I think we will just continue to talk at cross purposes.  I don't really understand your questions and it seems you don't understand my answers.

Roger

0
 
LVL 7

Author Comment

by:ayha1999
ID: 17988298
Hi,

I checked but it is different from my code I used to bind the datagrid. here is my code:

dim con as new sqlconnection("...
dim ad as new sqldataadapter
dim ds as new dataset

dim cmd as new sqlcommand("select...
con.open

ad.selectcommand=cmd
ad.fill(ds)

datagrid1.datasource= ds.Tables(0)

how can I update this adapter when changing items in the datagrid or should I used the same method explained in the link?

ayha
0
 
LVL 34

Accepted Solution

by:
Sancler earned 125 total points
ID: 17988590
Have a look at this recent answer

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_22048420.html#a17871205

That relates to OleDb dataobjects, but it is equally valid for Sql dataobjects.  It was also written in a VB.NET 2005 context, but it applies equally to 2003 if datagrid is substituted for datagridview and datasource is substituted for bindingsource.

Roger
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question