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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

how to find data type in grid

Thread ID:

Created:

Updated:

Platform:

Replies:

105688 Nov 13,2012 10:42 AM UTC Nov 26,2012 12:11 PM UTC Windows Forms 8
loading
Tags: GridControl
farooq
Asked On November 13, 2012 10:42 AM UTC

Hi 

I have a grid and I am trying to figure out the datatype of it. The first row has the headers and the remaining has the data. I want to put the grid into a data table so that I can use it to create a chart.

But I need to have the datatype in order to create the datatable. I am able to access the values in the grid using below code:

GridControl1.Item(1, 2).CellValue

But I want to be able to get the datatype as well.

farooq
Replied On November 13, 2012 10:48 AM UTC

I was able to search and find out how to find the data type. Below is what I am using:

MsgBox(TypeName(GridControl1.Item(1, 1).CellValue))

The problem is it is showing the data type as string even through the data in there is a number 8

I am new at VB and appreciate any help.

Arun Kumar V [Syncfusion]
Replied On November 15, 2012 01:02 PM UTC

Hi Farooq,

Thanks for your interest in Syncfusion products.

Query:

The problem is it is showing the data type as string even through the data in there is a number 8.

The value’s will be returned with string because if you bind values to the grid in the gridControl1.Text property. So please bind the values of the gridcontrol1.CellValue property to get the datatype.

Please refer to the code snippet.

Code snippet:

this.gridControl1[1, 1].CellValue = 32; //integer type.

//In a button click event...

MessageBox.Show(gridControl1[1, 1].CellValue.GetType().ToString());//this will return System.Int32...

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.

this.gridControl1[1, 1].Text = “32”; //string type.

//In a button click event...

MessageBox.Show(gridControl1[1, 1].CellValue.GetType().ToString());//this will return System.String...

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 

//If none of the datatype is provided it will return as string.

Please let me know if you have any other concerns.

Regards,

Arun.


farooq
Replied On November 17, 2012 07:28 AM UTC

Thanks for your reply. However, I am not binding the values through code but they would be provided by the user in the grid in the two ways mentioned below:

1- Importing a excel file: using this I am able to get the data type.

2- Copy pasting from excel. Using this the system type returned is string even though it is a number. Is there a way I can have the grid bind the values to the cell property instead of the text property?

Arun Kumar V [Syncfusion]
Replied On November 19, 2012 01:33 PM UTC

Hi Farooq,

 

Thanks for the update.

 

Query:

Get the celltype of the grid cell.

The required behavior can be customized by using the following file, please use the clipboardcanpaste  event and parsing the text will give the required actions.

Way2:

You can also make use of the following code.

gridControl1[row, col].CellValueType = typeof(int);

 

 

Sample : http://files2.syncfusion.com/dtSupport/DirectTrac/91031/Grid%20Selection-7584861.zip

 

Please let me know if you have any other concerns.

 

Regards,

Arun.


farooq
Replied On November 20, 2012 06:24 AM UTC

Hi Arun,


Can you please elaborate on way 2 for below code that you suggested:

gridControl1[row, col].CellValueType =typeof(int);

I cannot use this as the tpeof() method is returning string and the cellvaluetype would also be string.


Similar problem is that when the user types the value in the grid the typeof() is string even though the user is entering a number.




Arun Kumar V [Syncfusion]
Replied On November 20, 2012 11:50 AM UTC

Hi Farooq,

Please regret the inconvenience caused.

Query:

Get the celltype of the grid cell after a clipboard copy paste.

You can make use of the following Model.ClipboardCanPaste event for achieving the reported behavior. Please refer the following code snippet.

Note:

Default behavior of a grid cell is whenever you paste data into the grid cell the type will be set to string.

 

Code:

void Model_ClipboardCanPaste(object sender, GridCutPasteEventArgs e)

        {

            e.Result.GetTypeCode();

            MessageBox.Show(e.RangeList.ActiveRange.GetType().ToString());

            MessageBox.Show(gridControl1[1, 1].CellValue.GetType().ToString());

        }

 

 

Please let me know if you have any other concerns.

Regards,

Arun.


farooq
Replied On November 23, 2012 05:31 AM UTC

Hi,

below is the code that I am trying. I am working on VB so I would appreciate if you can share the code in vb

Imports Syncfusion.Windows.Forms.Grid

Public Class gridpasteproperty

    Private Sub gridpasteproperty_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Model_ClipboardCanPaste(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load



            e.Result.GetTypeCode(
        MsgBox(e.RangeList.ActiveRange.GetType().ToString())
        MsgBox(GridControl1(1, 1).CellValue.GetType().ToString())


    End Sub



End Class


I created a blank for and dropped the gridcontrol onto it. Kindly advise. Also how would I do it if the user enters the data manually.

Arun Kumar V [Syncfusion]
Replied On November 26, 2012 12:11 PM UTC

Hi Farooq,

Thanks for the update.

Query:

Get the celltype of the grid cell after a clipboard copy paste.

In this case I had implemented the required behavior in gridControl1.CurrentCellActivated

Event. Please make use the following code and revert us if the issue still exits.

Note:

Again we remaind you about Default behavior of a grid cell is whenever you paste data into the grid cell the type will be set to string.

Please refer to the code snippet.

Code:

Private Sub gridControl1_CurrentCellActivated(sender As Object, e As EventArgs)

         Dim str As String = gridControl1.CurrentCell.Renderer.ControlText

         Dim intValue As Int32

         Dim bigintValue As Int64

         Dim doubleValue As Double

         Dim boolValue As Boolean

         Dim dateValue As DateTime

         If Int32.TryParse(str, intValue) Then

                 MessageBox.Show("32 bit Integer value")

         ElseIf Int64.TryParse(str, bigintValue) Then

                 MessageBox.Show("64 bit Integer value")

         ElseIf Double.TryParse(str, doubleValue) Then

                 MessageBox.Show("Double value")

         ElseIf Boolean.TryParse(str, boolValue) Then

                 MessageBox.Show("boolean value")

         ElseIf DateTime.TryParse(str, dateValue) Then

                 MessageBox.Show("Datetime value")

         Else

                 MessageBox.Show("String")

         End If

End Sub

//………….

Now based on clicking the current cell the current cell value is reflected and its particular datatype is calculate.

Please let me know if you have any other concerns.

Regards,

Arun.


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;