none
Browse Form - Edit Form RRS feed

  • Question

  •  

    I have no Idea what I'm doing wrong. This is the third time I'm trying to post this thread and it does't show up after I clik Post button.

     

    Anyway, I'm a VC# newbie, trying to create an Windows Forms application which is using Access database. Let say there is a TestTable in the database, which is holding two columns (TestID and TestText).

     

    I made a Main form with a DataGridView (disabled its update capabilities) and provided the form with Insert, Change and Delete Buttons. This buttons shoul call another form (Edit Form) with nothing more than two textboxes, OK and Cancel buttons.

     

    Now I'd like to create a proper code for the btnChange_Click event and I don't now how. I figured out how to handle the Insert and Delete. I was searching through this forum and din't find anything that could help me (or I'm just not that familiar with the VC# to understand it).

     

    Here is the code, used for my Main form, for Insert record and Delete record.

     

     

    Code Snippet

    public Main()

    {

    InitializeComponent();

    }

    private void Form1_Load(object sender, EventArgs e)

    {

    // TODO: This line of code loads data into the 'testDBDataSet.TestTable' table. You can move, or remove it, as needed.

    this.testTableAdapter.Fill(this.testDBDataSet.TestTable);

    }

    private void btnClose_Click(object sender, EventArgs e)

    {

    this.Close();

    }

    private void BindingSourceSaveDB()

    {

    this.Validate();

    this.testTableBindingSource.EndEdit();

    this.testTableAdapter.Update(testDBDataSet.TestTable);

    }

    private void RefreshDataset ()

    {

    this.testTableAdapter.Fill(this.testDBDataSet.TestTable);

    }

    private void btnInsert_Click(object sender, EventArgs e)

    {

    EditForm dlgInsertRecord = new EditForm();

    dlgInsertRecord.ShowDialog();

    if (dlgInsertRecord.DialogResult == DialogResult.OK)

    {

    this.testTableAdapter.Insert(dlgInsertRecord.txtTest.Text);

    BindingSourceSaveDB();

    RefreshDataset();

    }

    else

    {

    testTableBindingSource.CancelEdit();

    RefreshDataset();

    }

    }

    private void btnDelete_Click(object sender, EventArgs e)

    {

    DialogResult response;

    response = MessageBox.Show("Do you realy want to delete this record?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);

    if (response == DialogResult.No)

    {

    return;

    }

    else

    {

    this.testTableBindingSource.RemoveAt(testTableBindingSource.Position);

    this.testTableBindingSource.EndEdit();

    this.testTableAdapter.Update(testDBDataSet.TestTable);

    }

    }

     

     

    Can omeone help me with this or point me into the right direction?

     

    Sorry, if my description is a bit confusing and for my "bad English".

     

    Thanks,

     

    Andrej

    Saturday, April 5, 2008 12:44 PM