0

For a windows application, I have a form with a gridview. In the form, I have an Edit button. If the user selects one row and clicks on Edit, it has to redirect to another form with the selected data. The user can then enter details in that. When the user clicks on Save Data, it should save and go back to the database.

FIRSTListForm

private void btnNewFIRSTList_ItemClick(object sender, ItemClickEventArgs e)`
{
    FIRSTEditForm FIRSTEditForm = new FIRSTEditForm(FIRSTID);`

    FIRSTEditForm.Show();

}

private void btnEditFIRSTList_ItemClick(object sender, ItemClickEventArgs e)
{
    //I need to know which row I selected before to Edit button

    //object IdFirst = ((GridView)sender).GetRowCellValue(e.RowHandle, "IDFIRST");

    //I need like a GetRowCellValue

    FIRSTEditForm.Show();
}
Jamal
  • 763
  • 7
  • 22
  • 32
user3117239
  • 1
  • 1
  • 2
  • 4
  • 1
    Could you post what you've tried so far? – Tom Dec 19 '13 at 00:07
  • 1
    As I understood your problem from your question and comments, you should update your question title. It doesn't sounds what you need. Like "how to edit selected row by using new form in datagridview" something like that – curiousBoy Dec 19 '13 at 00:32

3 Answers3

0

You need a save method to write your data back to your database and call it on your save button click

Here is multiple examples of exactly what your wanting

if you want to open a separate form then youll need something like This

Community
  • 1
  • 1
JayD
  • 6,173
  • 4
  • 20
  • 24
  • If user selects one row and click on edit, it must to redirect to another form and i dont know what to write to the Edit button – user3117239 Dec 18 '13 at 23:56
  • @user3117239: If you are talking about opening a new form, you can simply call your new form in edit button click event. Like : YourNewFormName newForm = New YourNewFormName(); newForm.ShowDialog(); – curiousBoy Dec 19 '13 at 00:20
  • You should edit your question, and paste your comment in it. Then people can understand easily what you need to do and can help you. It looks so complicated in comment section. Please update your question with details. That might help people to help you! – curiousBoy Dec 19 '13 at 00:30
0

If you're using Datasets with winforms you can try:
1)Check if your gridview has any selected rows first

if (gridView1.SelectedRowsCount > 0)
   {
         ......
   }

2) If that's the case using strongly named DataRow class and BindingSource.Current:

 YoutDataSet.YourTableOrResultSetRow Row;
 var P = YourTableOrResultSetBindingSource.Current as DataRowView;
 Row = (P.Row as YoutDataSet.YourTableOrResultSetRow );

 int id = Row.ColumnNameThatContainstheID; //this will give you the ID you're after
Milen
  • 8,697
  • 7
  • 43
  • 57
0

Try it sir,

private void gridView_DoubleClick(object sender, EventArgs e)
{
        if (gridView.GetFocusedRow() == null) return;

        if (gridView.GetFocusedRowCellValue("ID") == null) return;

        string id = gridView.GetFocusedRowCellValue("ID").ToString();

        FIRSTEditForm frm = new FIRSTEditForm(id);
        frm.Show();
}

In FIRSTEditForm use got ID and bind all your controls and save to database.

I use gridView_DoubleClick instead of your btnEditFIRSTList_ItemClick.

Hope it solves!

Triple K
  • 379
  • 1
  • 3
  • 14