Howdy
I have several tables on several datagrids and these tables have many rows and columns so to save time and typing ive set them up like so:
Do
While count < 6DtBalance.Columns.Add("",
GetType(String))count = count + 1
Loop For i = 1 To 37Row = DtBalance.NewRow
DtBalance.Rows.Add(Row)
DtBalance.AcceptChanges()
NextIve then set the rows to clear and be set as nothing like so:
Do
While i < DtBalance.Columns.Count Do While count < 37DgBalance.Item(count, i) = ""
count = count + 1
Loopcount = 0
i = i + 1
LoopThe problem now is that when i want to input numbers to the tables i cant cause they're all set to string. Can anyone tell me how i can get hold of selected columns to change tier data type
thx

Data columns
Sion380
Ok thats sorted the problem
thx
Sanghmitra
he problem is i want the majority of columns to be string its selected columns i want to be integer. Is there a way to change the data type of a column after ive added them all
Thx
Tony_DotNet
Yes, as I mentioned in my prevoius reply, you can change the DataType of a column after you have added it, but not after you have added data.
That means that in your code example, you can change it up until the point where you call Row = DtBalance.NewRow.
You just need to set the DataType property on the column that you want to change. You can get it from the DataTable.Columns collection after it's already been added. For example, right after your code finishes adding the columns, but before you start adding rows, add this line for a test:
DtBalance.Columns(0).DataType = GetType(Int32)
This will change the data type of the first column to Int32 instead of String.
If this doesn't work for you, please post an updated code sample and any errors that you are seeing.
Thanks,
Sarah
Bob Shaw
The data type is set on the DataColumn object, which you creating in this line of code:
If you want a different type, you need to set it there. For example, instead of GetType(String), use GetType("System.In32").
Also, you can change the DataType of a column before you have added any data to it, but once the data is added, the type cannot change.
Thanks,
Sarah