Click here to Skip to main content
15,912,493 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi All,

I have been trying this Since hours but not reaching anywhere.

I have a DataGridView which would fetch Values from the User and get updated at Runtime when he clicks the Save Button.
This Datagridview Contains Comboboxes and TextBoxes and to make things worst, the Inputs given by the User need to be saved as part of his Preferences.
Say He opens the Form, Provides an Input A - Clicks Save Button, Closes the Form. Then again Reopens the Form, Input A should be reflected.

The below code just displays Blank Columns in the DatagridView, The no. of Rows increment according to the Rows created by the User, but no Data is populated.
I know, I must be missing a lot of things but just not able to crack it.
Here is what I have till now:

//Form Load
C#
private void Preferences_Load(object sender, EventArgs e)
{

    this.WorkflowGridView1.DataSource = Properties.Settings.Default.WorkflowData;

}


I was trying to Save the Datasource in the Application Settings->Property Binding

C#
public void Save_Click(object sender, EventArgs e)
       {
           DTable = new DataTable();
           SBind = new BindingSource();

           for (int i = 0; i < WorkflowGridView1.ColumnCount; ++i)
           {
               DTable.Columns.Add(new DataColumn(WorkflowGridView1.Columns[i].Name));
               WorkflowGridView1.Columns[i].DataPropertyName = WorkflowGridView1.Columns[i].Name;

           }

           foreach (DataGridViewRow row in WorkflowGridView1.Rows)
           {
               DataRow rw = DTable.NewRow();
               rw["Technology"] = row.Cells[0].Value;
               rw["Action"] = row.Cells[1].Value;
               rw["Identifier"] = row.Cells[2].Value;
               rw["Value"] = row.Cells[3].Value;
               rw["UserInput"] = row.Cells[4].Value;
               DTable.Rows.Add(rw);
           }

           SBind.DataSource = DTable;
           WorkflowGridView1.DataSource = SBind;


           ////Saving the DataTable and Closing the Form when the Save Button is Clicked
           ////Here WorkfloData is the Variable for Application Settings having Datatable type.

           Properties.Settings.Default.WorkflowData = DTable;
           Properties.Settings.Default.Save();
           this.Close();
       }


P.S. I am looking out for a Solution through Application Settings only, Any help would be much appreciated.

Thanks
Sim
Posted
Updated 11-Mar-14 9:14am
v3
Comments
Sergey Alexandrovich Kryukov 11-Mar-14 16:07pm    
First, why application settings? You can use any persistence mechanism you prefer...
—SA
Simit1234 12-Mar-14 4:23am    
Which persistence mechanism can be best suited here, can you please elaborate , I Don't want to maintain an additional External File (XML, Excel etc) which would be generated on the fly.
In that case I have queries like,
Where would this File be stored?
This Utility would be used by the End User, what if the User Deletes that File by chance?
Is there any Considerable Performance hit in maintaining External Files?
TcJoshJohnson 30-Mar-14 0:19am    
User application settings are stored in an external XML file as well (kept by default in each user's AppData folder).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900