We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Retrieving/Saving Records to Database

Hi! Im new to syncfusion and I used VB2005. I am trying to create a grading system.My concerns are very basic...
1. How do retrieve records from my sql?
2. How do I assign formula? programatically (preferred) or through designer if any. Say in column A students name will display, Column B contains total Assign given by the teacher, in Column C teacher will enter scores of each students and in Column C i want to have a formula like =((A1/B1)*60 + 40).
3. Saving any changes to the database



6 Replies

NA Nisha Arockiya A Syncfusion Team September 11, 2008 12:03 PM UTC

Hi,

Thanks for your interest in Syncfusion products.

1)How to retrieve records from my sql?
Initially load the dataset to the grid using the following code snippet.
//load the dataset
this.sqlDataAdapter1.Fill(this.dataSet11);

After loading you can retrieve records from the Grid itself.

2)How do I assign formula?
You can assign formula to a whole column by setting ColStyles[colIndex].Text to specific formula of the FormulaCell celltype.

Me.GridControl1.ColStyles[3].CellType = "FormulaCell"
Me.GridControl1.ColStyles[3].Text = "=((A1/B1)*60 + 40)"



3)Saving any changes to the database

If you are using the VS designer to add your daatset and datatable, if you allow it to generate Update commands, then you only have to call this.sqlDataAdapter1.Update to have the dataadapter move the changes back to the data source. This is analogous to the this.sqlDataAdapter1.Fill command that retrieves the information when the data is originally loaded.

In the samples listed below, there are Form_Closing events taht have commented code in them that would do the update.


Syncfusion\Essential Suite\Grid\Samples\DataBound\GDBGMultiHeader

Syncfusion\Essential Suite\Grid\Samples\DataBound\RecordNavDataBoundGrid


Please let me know any clarifications.

Regards,
Nisha


>Hi! Im new to syncfusion and I used VB2005. I am trying to create a grading system.My concerns are very basic...
1. How do retrieve records from my sql?
2. How do I assign formula? programatically (preferred) or through designer if any. Say in column A students name will display, Column B contains total Assign given by the teacher, in Column C teacher will enter scores of each students and in Column C i want to have a formula like =((A1/B1)*60 + 40).
3. Saving any changes to the database






LG lg_sony_27 September 12, 2008 12:14 AM UTC

Thank you for the quick reply. I noticed that you mostly used C# in your sample code here, I am using vb2005 is any possibilities that you show examples in VB?

I have some other concerns.

1. if I have "(A1 + B1)" formula in C1, will this automatically apply/compute for values in A2 and B2 in C2 and so on?
2. how do I create tab sheets?
3. Is there drag and fill (autofill) feature?
4. How do I change the Header value?
5. How to make the cellpointer move to next row when enter key is pressed.
6. Sort columns (ex. Column A - LastName, Column B - FirstName, Column C - Gender. Column C is the primary key sorted Descending and Column A is the secondary key sorted Ascending.



NA Nisha Arockiya A Syncfusion Team September 12, 2008 01:20 PM UTC

Hi,

1. if I have "(A1 + B1)" formula in C1, will this automatically apply/compute for values in A2 and B2 in C2 and so on?
---------------------
You can copy formulas into adjacent cells by using the fill handle (fill handle: The small black square in the lower-right corner of the selection. When you point to the fill handle, the pointer changes to a black cross.) can be achieved by using the ExcelMarkerMouseController, which could be found in the \Syncfusion\Essential Suite\Grid\Samples\In Depth\ExcelSelectionMarker sample, and by setting the FormulaCopyFlags of GridFormulaEngine as mentioned below.


GridFormulaEngine engine = ((GridFormulaCellModel)this.gridControl1.CellModels["FormulaCell"]).Engine;
engine.FormulaCopyFlags |= GridFormulaCopyFlags.ClipBoardReferencesAdjusted;


The first cell value should be copied and pasted in all the dragged cells in the MouseUp event of the ExcelMarkerMouseController.

Please refer to the sample given below which illustrates the above:

http://websamples.syncfusion.com/samples/Grid.Windows/I40755/main.htm

2)How do I create tab sheets?
You can create tab sheets using the following code snippet:

WorkbookModel workbook;
workbook = new WorkbookModel("Workbook");
GridModel sheet1 = new GridModelEx();
SampleGrid.SetupGridModel(sheet1);
workbook.Worksheets.Add(new WorksheetModel(workbook, "Sheet 1", sheet1));


3)Is there drag and fill (autofill) feature?

Please refer to the following browser sample for drag support.

\Syncfusion\EssentialStudio\6.3.0.30\Windows\Grid.Windows\Samples\2.0\DragDropSupport\

Take a look at the Syncfusion\Essential Suite\Grid\Samples\In Depth\ExcelSelectionMarker sample. In that sample, if you position the cursor over the bottom right corner of a cell or selection, you get a special drag cursor that allows you to expand the selection by dragging. When you release the drag, in the sample a message box pops up that gives you the range selected. At that point, you could do your auto-fill. Now the sample does not actually do the autofill, but depending on what you want to do, you could use grid.ChangeCell to change the whole range to have the same style as the top left cell. Or, you could just loop through the range, explicitly setting values in some logical way depending upon what you want.

4) How do I change the Header value?
You can change the column header text using the following code snippet.

if (e.ColIndex == 1 && e.RowIndex == 0)
{
e.Style.Text = "Data Creazione";
}


5)How to make the cellpointer move to next row when enter key is pressed.
For that you need to handle CurrentCellControlKeyMessage event.

private void gridControl1_CurrentCellControlKeyMessage(object sender, GridCurrentCellControlKeyMessageEventArgs e)
{
if(Keys.keyCode == Keys.Enter)
{
this.gridControl1.CurrentCell.MoveTo(ro+1,col);
}
}


6)Sort columns
Please refer this forum thread, which deals with multicolumn sorting in a gridcontrol and let me know if this helps.
Example on How to Multi-Column Sort with GridControl

Please let me know if this helps.

Retgards,
Nisha


>Thank you for the quick reply. I noticed that you mostly used C# in your sample code here, I am using vb2005 is any possibilities that you show examples in VB?

I have some other concerns.

1. if I have "(A1 + B1)" formula in C1, will this automatically apply/compute for values in A2 and B2 in C2 and so on?
2. how do I create tab sheets?
3. Is there drag and fill (autofill) feature?
4. How do I change the Header value?
5. How to make the cellpointer move to next row when enter key is pressed.
6. Sort columns (ex. Column A - LastName, Column B - FirstName, Column C - Gender. Column C is the primary key sorted Descending and Column A is the secondary key sorted Ascending.





LG lg_sony_27 September 13, 2008 12:33 AM UTC

Hi!
What I mean by this is, I want that whenever the user will type in values during runtime say in columns A and B the Column C will automatically compute it.

When I put this code
Me.GridControl1.ColStyles[3].CellType = "FormulaCell"
Me.GridControl1.ColStyles[3].Text = "=((A1/B1)*60 + 40)"
The cell reference should be relative. whether the user will input in A50 and B50 it will still compute.

I don't know C#. Can you post the code in its VB equivalent? Thanks!

>Hi,

1. if I have "(A1 + B1)" formula in C1, will this automatically apply/compute for values in A2 and B2 in C2 and so on?
---------------------
You can copy formulas into adjacent cells by using the fill handle (fill handle: The small black square in the lower-right corner of the selection. When you point to the fill handle, the pointer changes to a black cross.) can be achieved by using the ExcelMarkerMouseController, which could be found in the \Syncfusion\Essential Suite\Grid\Samples\In Depth\ExcelSelectionMarker sample, and by setting the FormulaCopyFlags of GridFormulaEngine as mentioned below.


GridFormulaEngine engine = ((GridFormulaCellModel)this.gridControl1.CellModels["FormulaCell"]).Engine;
engine.FormulaCopyFlags |= GridFormulaCopyFlags.ClipBoardReferencesAdjusted;


The first cell value should be copied and pasted in all the dragged cells in the MouseUp event of the ExcelMarkerMouseController.

Please refer to the sample given below which illustrates the above:

http://websamples.syncfusion.com/samples/Grid.Windows/I40755/main.htm







LG lg_sony_27 September 13, 2008 01:23 AM UTC

By the way, I will be using the GDBG. I was trying to GridControl but I cant bind it to my datasource.



NA Nisha Arockiya A Syncfusion Team September 16, 2008 11:10 AM UTC

Hi,

Thanks for your updates.

You can set the grid to update references when you copy/paste them by setting this flag in the 2.0 versions.


GridFormulaEngine engine = ((GridFormulaCellModel)this.gridControl1.CellModels["FormulaCell"]).Engine;

engine.FormulaCopyFlags |= GridFormulaCopyFlags.ClipBoardReferencesAdjusted;


Please refer to the following location for the sample code in VB.
http://websamples.syncfusion.com//samples/Grid.Windows/Development/ForumlaDragVB.zip


Please let me know if this helps.

Regards,
Nisha

>By the way, I will be using the GDBG. I was trying to GridControl but I cant bind it to my datasource.




Loader.
Live Chat Icon For mobile
Up arrow icon