Doable:edit rows?

eramgarden

Contributor
Joined
Mar 8, 2004
Messages
579
I know this is doable in ASP.Net: Bind data to datagrid, then click on an , for example, "edit" column of the row and edit the information ...

How can I do this in WinForms:
1. I know I can use a DataGrid and Bind data to it..

2. Do I need to pop-up another Form for editing??

I've search google a lot but not many examples.
 
What are you asking, how to mod data in a datgrid ???

If this is it, then do as you did in ASP, bind the data to the datagrid and when you type in the grid, the data should be updated for you.
 
hmm..

In asp.net , I had something like this for example (in the datagird)

Update Name1 Address1 Phone1
Update Name2 Address2 Phone2

When I clicked on a row (on update column), I got another page with the information where I could edit, cancel, update...

How is this done in WinForms?? I CAN bind to Datagrid, I know that, but how is the updating/editing of rows are done??

Any examples?
 
Once you have bound your data source to the datagrid and the datagrid is not set as readonly then all you have to do is type in the cells in the grid and the datasource will be updated automatically. Just try it, it is not too difficult. The buildin help in VS will give you some help.
 
My manager changed the criteria:

1. have an edit button next to each row and pop-up a box to edit the cell...

2. If double click in the cell, pop-up a box and edit the cell in the pop-up box..

any examples?
 
What on earth are ye trying to do, bring ASP restricted functionality into a windows app. I have never seen a windows app that works the way ye want it to do. Yier end users will not like it.

Try what I suggested, it does work.


Download Micrisoft's 101 .NET samples, that will help you as yes seem to be a bit lost on how windoes apps can work.
 
I get these instructions from my manager..he said he's done WinForm applications before..

it's his idea to have edit buttons, then have a box pop-up to edit...

I found examples and you're right, it's not that hard. He says it's easier for users to have it pop-up...

But one question: Is it doable the way he says??
 
Yes, its doable.

Create a form that takes a DataRowView in its constructor. From the DataRowView, populate the various controls on the form and allow the user to edit. Set the OK/Cancel buttons to DialogResult.OK and DialogResult.Cancel.

Then, in the doubleclick event of the datagrid, find the currently selected row (.SelectedRow iirc?) and pass it (probably with a bit of Typing or casting) into an instance of your form, then show it using .ShowDialog. If the result of .ShowDialog is Ok, then return the values form the controls into the DataRowView (you can use binding, but I find it very inflexible)

Then, when you've finished with the form displaying the grid itself, call your relevant DataAdapter.Update(Datatable) method to flush the changes back to the database.

B.
 
Seems like a lot of work..but this is not the default fucntionality of Datagrid in WinForms..is it?? Seems like the default functionality is as Hamlet described..is this correct?
 
Yes, the default is as Hamlet described - I was merely showing that what you want to achieve *is* doable, its just not trivial.

B.
 
Penfold69 is right in how to do it, there are other ways as well but all of them require a fair bit of coding/management to implement something that is already present as the default functionality.

Have fun with your boss.
 
My boss wants to make it easy for Project managers when they're using the app..but i really think if they're that stupid that they cant type in a cell..then they shouldnt be using the app anyway :D
 
Having worked as a project manager for years, nothing annoys me more than having to do stuff the isin't necessart and can be done easier. As a project manager this feature would be more than enough to annoy me and stop me buying....

Our goal is to make the end users life easier, otherwise they might as well use a piece of paper....
 
I just want to say something...

It appears to me that your boss is kind of stuck on the Web way of appearance and shure the business layer will also reflect that way of think...

Now, it's up to you to make your life (at work) more pleasant... show him that there are plenty of other way, easyer and mor intuitive ways, of do things in Windows.Forms environment...

This is just an advise...
This kind of behaviour is what makes an employee a future boss... :p

Alex
 
Back
Top