By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,046 Members | 2,058 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,046 IT Pros & Developers. It's quick & easy.

Datagrid column width won't change

P: n/a
Ben
Could someone please tell me why couldn't I adjust my column/row properties
of my dataGrid? I binded my table, created a new DataGridTableStyle and
mapped it to my datagrid. However, my columns width wouldn't changed at all.
I am sure this is very easy thing to figure out but I just couldn't see it.
Could you please take a look at my codes. What I am missing? Btw, I got
these codes from MSDN website:

thanks.

.....
Private myDataGrid As DataGrid
Private myDataSet As DataSet
Private TablesAlreadyAdded As Boolean
Private ts1 As New DataGridTableStyle
....

from my default constructor, I rand SetUp()
......
Private Sub SetUp()
'create a dataset with two tables and one relation.
MakeDataSet()
'bind the datagrid to the dataset. the datamember
'specifies that the customers table should be displayed.
myDataGrid.SetDataBinding(myDataSet, "customers")

Dim ts1 As New DataGridTableStyle
ts1.MappingName = "customers"
Dim myDataCol As New DataGridBoolColumn
myDataCol.HeaderText = "My New Column"
myDataCol.MappingName = "current"
myDataCol.Width = 4000000
ts1.GridColumnStyles.Add(myDataCol)
myDataGrid.TableStyles.Add(ts1)

End Sub
.....................along that path, it should execute this dataset then
bind to myDataGrid
Private Sub MakeDataSet()
myDataSet = New DataSet("myDataSet")

Dim tCust As New DataTable("Customers")
Dim cRecordName As New DataColumn("Record Name", GetType(Integer))
Dim cUnitOfMeasurement As New DataColumn("Unit Of Measurement")
Dim cSimulationCaseNo As New DataColumn("Simulation Case Number")
tCust.Columns.Add(cRecordName)
tCust.Columns.Add(cUnitOfMeasurement)
tCust.Columns.Add(cSimulationCaseNo)

myDataSet .Tables.Add(tCust)

Dim newRow1 As DataRow

Dim i As Integer
For i = 1 To 3
newRow1 = tCust.NewRow()
newRow1("Record Name") = i
tCust.Rows.Add(newRow1)
Next i
tCust.Rows(0)("Unit Of Measurement") = "Customer1"
tCust.Rows(1)("Unit Of Measurement") = "Customer2"
tCust.Rows(2)("Unit Of Measurement") = "Customer3"

tCust.Rows(0)("Simulation Case Number") = "asdf"
tCust.Rows(1)("Simulation Case Number") = "asdf"
tCust.Rows(2)("Simulation Case Number") = "asdfdas"
End Sub
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

The mappingname for the tablestyle is case sensitive. Try
using Customers instead of customers. Not sure if the datagrid supports
column widths of 4000000

Ken
--------------------
"Ben" <Be*@discussions.microsoft.com> wrote in message
news:2A**********************************@microsof t.com...
Could someone please tell me why couldn't I adjust my column/row properties
of my dataGrid? I binded my table, created a new DataGridTableStyle and
mapped it to my datagrid. However, my columns width wouldn't changed at
all.
I am sure this is very easy thing to figure out but I just couldn't see it.
Could you please take a look at my codes. What I am missing? Btw, I got
these codes from MSDN website:

thanks.

.....
Private myDataGrid As DataGrid
Private myDataSet As DataSet
Private TablesAlreadyAdded As Boolean
Private ts1 As New DataGridTableStyle
....

from my default constructor, I rand SetUp()
......
Private Sub SetUp()
'create a dataset with two tables and one relation.
MakeDataSet()
'bind the datagrid to the dataset. the datamember
'specifies that the customers table should be displayed.
myDataGrid.SetDataBinding(myDataSet, "customers")

Dim ts1 As New DataGridTableStyle
ts1.MappingName = "customers"
Dim myDataCol As New DataGridBoolColumn
myDataCol.HeaderText = "My New Column"
myDataCol.MappingName = "current"
myDataCol.Width = 4000000
ts1.GridColumnStyles.Add(myDataCol)
myDataGrid.TableStyles.Add(ts1)

End Sub
.....................along that path, it should execute this dataset then
bind to myDataGrid
Private Sub MakeDataSet()
myDataSet = New DataSet("myDataSet")

Dim tCust As New DataTable("Customers")
Dim cRecordName As New DataColumn("Record Name", GetType(Integer))
Dim cUnitOfMeasurement As New DataColumn("Unit Of Measurement")
Dim cSimulationCaseNo As New DataColumn("Simulation Case Number")
tCust.Columns.Add(cRecordName)
tCust.Columns.Add(cUnitOfMeasurement)
tCust.Columns.Add(cSimulationCaseNo)

myDataSet .Tables.Add(tCust)

Dim newRow1 As DataRow

Dim i As Integer
For i = 1 To 3
newRow1 = tCust.NewRow()
newRow1("Record Name") = i
tCust.Rows.Add(newRow1)
Next i
tCust.Rows(0)("Unit Of Measurement") = "Customer1"
tCust.Rows(1)("Unit Of Measurement") = "Customer2"
tCust.Rows(2)("Unit Of Measurement") = "Customer3"

tCust.Rows(0)("Simulation Case Number") = "asdf"
tCust.Rows(1)("Simulation Case Number") = "asdf"
tCust.Rows(2)("Simulation Case Number") = "asdfdas"
End Sub
Nov 21 '05 #2

P: n/a
Ben,

Mostly these errors come if you don't use the same cases as you do in your
code
This part is with windowsforms programming case sensitive (rarely it is not
with a webform datagrid).

I hope this helps,

Cor
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.