Rapid Application Development (RAD) With The DataGridVIew

Earlier this week, I came across a new developer who was trying to loop through his DataGridView to get the data out of it. Usually, RAD development with the DataGridView just does not work for most of my business scenarios but here was a clear case where it worked well so I will paste my instructions here:

1. Create your form.

2. Drag a DataGridView to your form. A pop-up window entitled “DataGridView Tasks” should appear. If not, then there should be a small arrow in the top right-hand corner of the DataGrid.

3. From here, select “Choose Data Source –> Add Project Data Source.” This should trigger a wizard that will assist you in setting up your database connection. Select “Database”, then select your table, and continue to walk through the wizard.

4. If you return to your form, you should now see a DataSet, a BindingSource, and a TableAdapter. These are the tools that you will use to get and save your DataGrid data.

5. Note that in your Form_Load event, there should be a like of code similar to the following:

this.tableAdapter.Fill(this.dataSet1.table);

6. Now, add a button to your form and create a _Click event. Here you should be able to save your data by entering your version of the following lines of code:

this.Validate();
this.tableBindingSource.EndEdit();
this.tableAdapter.Update(dataSet1.table);

7. The data should now be updated in your DataGrid and database.

This code will fill your DataGridView upon load. You can modify the SQL in the DataSet to pull only select data if you wish.

http://msdn.microsoft.com/en-us/library/ms171933(v=vs.80).aspx

Convert Comma-Delimited String To Array & Loop

–set whatever delimiter you want to use:
char delimiter = ‘,’;

–Get the string you want to turn to an array (in this case, I use the app.config)
string s = ConfigurationManager.AppSettings[“StringToReplace”];

–Declare an array for your string
string[] stringToReplace = s.Split(delimiter);

–Finally, if you want to loop through your new array:
string content = String.Empty;

for (int j = 0; j <> 0; j++)
{
content = stringToReplace[j];
}

Error: Option Strict On disallows operands of type Object for operator ‘<>‘.

This is a fairly easy error to fix :

Error 55 Option Strict On disallows operands of type Object for operator ‘<>‘. Use the ‘Is’ operator to test for object identity.

Chances are, you have a line of code like this:

If (Me._item <> Value) Then

Change it to this:

If Not (Me._item Is Value) Then

Of course, you could always try setting Option Strict off, but that is usually not the best practice.

Visual Studio ShortCut Keys

Ever since the post-Visual-Studio-6 era, I’ve had a difficult time keeping my shortcut keys in order. I am used to using CTRL-G to get to my line numbers almost instantly but none of the new Visual Studios seem to come with this pre-set and, since I don’t have to do it everyday, I forget how. Anyway, here is my snippet on setting shortcuts, specifically CTRL-G for line numbers:

  • First, if you have not already, turn on line numbers: navigate to Tools –> Options –> Text Editor –> All Languages –> then check to display ‘Line Numbers.’
  • Second, again navigate to Tools –> Options –> Environment –> Keyboard –> select “Edit.GoTo” as the command then press “CTRL-G’”under the ‘Press shortcut keys’ and, finally, click “OK.”

Simple, and probably obvious to everyone but myself. 😀