Bryan01

I was wondering how could I make a row in a data grid from just except integers When I add data to the Data Grid with the program it puts in integers in one of the colunms and when a user puts numbers in that same column it comes up as a string I think and gives an error when trying to sort by that column. Is there a way to make the data inputed by the user compatible with the data inputed by the program (if the program puts strings in the column it does not sort properly. It will place 12 after 15 as lowest, only looking at the 1 and then looking at the second number.


Re: Visual Basic Express Edition Data Grid View

ReneeC

Look at the database and the datatype of the column. The DGV is reflecting that the datatype.






Re: Visual Basic Express Edition Data Grid View

Bryan01

Were might I find the database and datatype of a column This information can not be found under the edit column window.




Re: Visual Basic Express Edition Data Grid View

js06

in the database explorer - right click on the table and then click open table definition

check you column data type

probably needs to be - int






Re: Visual Basic Express Edition Data Grid View

Bryan01

I do not have the data grid connected to a data source. All I use it for is to create a user editable list that can be sorted by a column (highest number to lowest number). Is there a better way of doing this




Re: Visual Basic Express Edition Data Grid View

Bryan01

Does anyone have an answer to this question




Re: Visual Basic Express Edition Data Grid View

ReneeC

" Is there a way to make the data inputed by the user compatible with the data inputed by the program "

Datagridview <------- Cint(UserInputValue)

You know more about the way you have this wired up than i do. So I just showed you how to the conversion.






Re: Visual Basic Express Edition Data Grid View

Bryan01

What Im trying to ask is: Is there a way for a column in a DantaGridView only to except integers in for that column The datagidview is not associated with a database, it is just in the program.



Re: Visual Basic Express Edition Data Grid View

Dave299

DataGridView1.Columns(0).ValueType = (New Integer).GetType

will only allow you to enter integers into Column0 and will also ensure that they are sorted correctly.

To handle incorrect entries handle the DataError event, something like this:

Private Sub DataGridView1_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles DataGridView1.DataError

If e.Context = (DataGridViewDataErrorContexts.Parsing Or DataGridViewDataErrorContexts.Commit Or DataGridViewDataErrorContexts.CurrentCellChange) And e.ColumnIndex = 0 Then

MsgBox("Invalid entry")

End If

End Sub





Re: Visual Basic Express Edition Data Grid View

ReneeC

Or

DataGridView1.Columns(0).ValueType = System.Type.GetType("System.Int32")

Be careful when you do that through the "System.Int32" is case sensitive.