mrdutchie Posted April 28, 2004 Posted April 28, 2004 Hi there, if someone could help me with this, I would really appriciate that. When I import a testfile into a datagrid I am able to sort the columns but column 2 and 3 are numbers, so those are not sorting right since it is a String. I tried to make it as a Int32, Int16 but then it's failing on this line "myDataSet.Tables(ImportFileName).Columns.Add(myColumn)" I only can import it as a string. I can't figure out how to do it as a number or Int. What do I need to do to make it work?? Thanks so much Public Sub ExecutImport() Dim myReader As New System.IO.StreamReader(clsFileAndPath) Dim CurrentLine As String Dim IsFirstLine As Boolean Dim myTable As New DataTable Dim SqlTable As New DataTable Dim ColumnName As String Dim tmpCount As Integer Dim ColumnCount As Integer Dim myColumn As DataColumn Dim myRowSql As DataRow Dim myRowTable As DataRow Dim RowCount As Integer Dim ImportFileName As String Dim aa() As String Dim bb As Long Dim cc As Long Dim dd() As String clsTotalRows = GetTotalRows() If clsCrossRefTableName <> "" Then Dim myConnection As New SqlClient.SqlConnection(clsCrossRefTableConString) Dim myCommand As New SqlClient.SqlCommand(clsCrossRefTableFillCmd) Dim daCRT As New SqlClient.SqlDataAdapter(myCommand) myCommand.Connection = myConnection SqlTable = New DataTable(clsCrossRefTableName) myDataSet.Tables.Add(clsCrossRefTableName) daCRT.Fill(myDataSet.Tables(clsCrossRefTableName)) End If ImportFileName = FileName myTable = New DataTable(ImportFileName) myDataSet.Tables.Add(ImportFileName) While myReader.Peek <> -1 CurrentLine = myReader.ReadLine If IsFirstLine = False Then myColumn = New DataColumn("Group") myDataSet.Tables(ImportFileName).Columns.Add(myColumn) 'myColumn.DataType = System.Type.GetType("System.Int32") myColumn.DataType = System.Type.GetType("System.String") myColumn = New DataColumn("Start") myDataSet.Tables(ImportFileName).Columns.Add(myColumn) 'myColumn.DataType = System.Type.GetType("System.Int32") myColumn.DataType = System.Type.GetType("System.String") myColumn = New DataColumn("End") myDataSet.Tables(ImportFileName).Columns.Add(myColumn) aa = CurrentLine.Split(" ") bb = CInt(aa(1)) cc = CInt(aa(2)) myDataSet.Tables(ImportFileName).Rows.Add(aa) myRowTable = myDataSet.Tables(ImportFileName).Rows(RowCount) RowCount += 1 End If If IsFirstLine = False Then IsFirstLine = True tmpCount = 0 Else myDataSet.Tables(ImportFileName).Rows.Add(CurrentLine.Split(" ")) myRowTable = myDataSet.Tables(ImportFileName).Rows(RowCount) RowCount += 1 End If End While clsImportedDataSet = myDataSet End Sub Quote
Arch4ngel Posted April 28, 2004 Posted April 28, 2004 myDataSet.Tables(ImportFileName).Columns.Add(myColumn, typeof(int)) that doesn't work ? What do you mean by sorting ? By clicking in the column header of our DataGrid ? Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
mrdutchie Posted April 28, 2004 Author Posted April 28, 2004 It's working now.. duh had 2 lines in the wrong order PREV 'myColumn.DataType = System.Type.GetType("System.Int32") myColumn.DataType = System.Type.GetType("System.String") myColumn = New DataColumn("Start") myDataSet.Tables(ImportFileName).Columns.Add(myColumn) 'myColumn.DataType = System.Type.GetType("System.Int32") myColumn.DataType = System.Type.GetType("System.String") myColumn = New DataColumn("End") myDataSet.Tables(ImportFileName).Columns.Add(myColumn) NOW myColumn = New DataColumn("Start") myColumn.DataType = System.Type.GetType("System.Int32") myDataSet.Tables(ImportFileName).Columns.Add(myColumn) myColumn = New DataColumn("End") myColumn.DataType = System.Type.GetType("System.Int32") myDataSet.Tables(ImportFileName).Columns.Add(myColumn) Quote
Arch4ngel Posted April 28, 2004 Posted April 28, 2004 LOL. Yeah... it sure doesn't save changes made to a columns if you don't add it before ! :p Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
mrdutchie Posted April 28, 2004 Author Posted April 28, 2004 lol.. Yep and I was looking at it for over a week... :o Quote
Arch4ngel Posted April 28, 2004 Posted April 28, 2004 If you want a good solution for finding error of this kind... Follow this... take a friend that is a programmer put him in front of your code (without explaining him the problem) and ask him if he found something "stupid". While he look at your code, take a beer and watch him. That always work for me... and I find those error more often than even. Beer is a miracle ;) Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
mrdutchie Posted April 28, 2004 Author Posted April 28, 2004 Hehe... you have Experience with that I see... I'll keep it in mind for next time.... hmm... any Idea how to put a checkbox in a column easy? playing with that now...but no luck so far Quote
Arch4ngel Posted April 28, 2004 Posted April 28, 2004 Have you try this : DataRow r = dt.New(); CheckBox cb = new CheckBox(); cb.Text = "Something"; r[0] = cb; [edit] do the same if it's a DataGrid. I didn't try this yet.[/edit] Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
mrdutchie Posted April 28, 2004 Author Posted April 28, 2004 Yeah I tried something like that, and even your code. but doesn't work. Quote
Arch4ngel Posted April 28, 2004 Posted April 28, 2004 If your project is ASP : http://www.codeproject.com/aspnet/DataGridCheckBox.asp If your project is Windows : http://www.knowdotnet.com/articles/kdngrid.html By looking at those web sites, you could get the answer to your questions. Stay Zen. :p Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
mrdutchie Posted April 28, 2004 Author Posted April 28, 2004 Thanks.. My project is Windows, let's see if I can get smarter with that one.. Quote
Arch4ngel Posted April 28, 2004 Posted April 28, 2004 It was a pleasure to help my programmer friend. Don't hesitate to ask again ;) Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
mrdutchie Posted April 28, 2004 Author Posted April 28, 2004 Well... I'm back for some reason I don't have those command available for my datagrid. I'm totally puzzled with this line (this is a modified source I found for a datagrid) myDataSet.Tables(ImportFileName).Rows.Add(aa) aa is some kind of array a(0)="a.b.test" a(1)="34" a(2)="345" Still unable to add a checkbox because of that line. So I have in my textfile "False a.b.test 34 345" So the first value will fill the checkbox for me, and that works.. (I am sure there is a better way) But I want to change the columnwidth from 1 of the columns, but I don't have the right command showing up when I type. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.