resizing the width of columns in datagrid with datatable
-
Hello I want to set the width of each columns in datagrid separately but not able to do that. I am using datagrid and datatable in my project the codes are as follows. Dim Mytable as new datatable Mytable.columns.add(“srno”, gettype, string)) Mytable.columns.add(“name”, gettype,( string)) Mytable.columns.add(“designation”, gettype,( string)) Mytable.columns.add(“remarks”, gettype,( string)) Datagrid1.datasourse = mytable datagrid1.preferredcoloumswidth = 74 Now my problem is all the coloumns are OF the same width, as I wanted different width of different column. As of now all the columns have the same width whereas I don’t need so much width for the SRNO and need more wider colums in REMARKS. Please suggest how can I solve this problem. Thanks alot
-
Hello I want to set the width of each columns in datagrid separately but not able to do that. I am using datagrid and datatable in my project the codes are as follows. Dim Mytable as new datatable Mytable.columns.add(“srno”, gettype, string)) Mytable.columns.add(“name”, gettype,( string)) Mytable.columns.add(“designation”, gettype,( string)) Mytable.columns.add(“remarks”, gettype,( string)) Datagrid1.datasourse = mytable datagrid1.preferredcoloumswidth = 74 Now my problem is all the coloumns are OF the same width, as I wanted different width of different column. As of now all the columns have the same width whereas I don’t need so much width for the SRNO and need more wider colums in REMARKS. Please suggest how can I solve this problem. Thanks alot
You have to modify the DataGrids TableStyles collection to get at the column widths.
Dim ts As DataGridTableStyle = DataGrid1.TableStyles("columnName")
ts.Width = someValueRageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
You have to modify the DataGrids TableStyles collection to get at the column widths.
Dim ts As DataGridTableStyle = DataGrid1.TableStyles("columnName")
ts.Width = someValueRageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
I tried the one you suggested Dim ts as datagridtablestyle = datagrid1.tablestyles(“REMARKS”) Ts.preferredcoloumns = 100 I HAD THIS ERRORS “Object reference not set to an instance of an object” Kindly check pls. Thanks alot for your time.
Sorry, I had rectal-cranial inversion...
DataGrid1.DataSource = ds.Tables("MyTable") Dim ts As New DataGridTableStyle ts.MappingName = "MyTable" DataGrid1.TableStyles.Add(ts) ts.GridColumnStyles(0).Width = 15
RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
Sorry, I had rectal-cranial inversion...
DataGrid1.DataSource = ds.Tables("MyTable") Dim ts As New DataGridTableStyle ts.MappingName = "MyTable" DataGrid1.TableStyles.Add(ts) ts.GridColumnStyles(0).Width = 15
RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
Sorry but it still has erros I tried you codes but still I have one more error sending you my declarations DECLARATION Dim mytable As New DataTable Dim ds As New DataSet ON FORM LOAD mytable.Columns.Add(New DataColumn("ContactPerson", GetType(String))) mytable.Columns.Add(New DataColumn("DESIGNATION", GetType(String))) mytable.Columns.Add(New DataColumn("PHONENO", GetType(String))) mytable.Columns.Add(New DataColumn("EXTN", GetType(String))) mytable.Columns.Add(New DataColumn("CELLNO", GetType(String))) mytable.Columns.Add(New DataColumn("SALESMAN", GetType(String))) mytable.Columns.Add(New DataColumn("REMARKS", GetType(String))) Me.DataGrid1.DataSource = ds.Tables("mytable") Dim ts As New DataGridTableStyle ts.MappingName = "mytable" DataGrid1.TableStyles.Add(ts) Me.DataGrid1.DataSource = mytable ts.GridColumnStyles(0).Width = 100 ERROS IS HERE (index is out of range: MUST BE NEGATIVE AND LESS THAN THE SIZE OF THE COLLECTIONS) Thanks again for you help and you Suggestionss Thanks again Regards :(
-
Sorry but it still has erros I tried you codes but still I have one more error sending you my declarations DECLARATION Dim mytable As New DataTable Dim ds As New DataSet ON FORM LOAD mytable.Columns.Add(New DataColumn("ContactPerson", GetType(String))) mytable.Columns.Add(New DataColumn("DESIGNATION", GetType(String))) mytable.Columns.Add(New DataColumn("PHONENO", GetType(String))) mytable.Columns.Add(New DataColumn("EXTN", GetType(String))) mytable.Columns.Add(New DataColumn("CELLNO", GetType(String))) mytable.Columns.Add(New DataColumn("SALESMAN", GetType(String))) mytable.Columns.Add(New DataColumn("REMARKS", GetType(String))) Me.DataGrid1.DataSource = ds.Tables("mytable") Dim ts As New DataGridTableStyle ts.MappingName = "mytable" DataGrid1.TableStyles.Add(ts) Me.DataGrid1.DataSource = mytable ts.GridColumnStyles(0).Width = 100 ERROS IS HERE (index is out of range: MUST BE NEGATIVE AND LESS THAN THE SIZE OF THE COLLECTIONS) Thanks again for you help and you Suggestionss Thanks again Regards :(
It doesn't work because you reset the DataSource of the DataGrid, wiping out all the changes made to the TableStyles. Why are you adding all the Columns? You really don't need to unless your going to customize the look of them, which you're not doing in your code.
' I hope your DataSet actuall yhas a table in it called mytable.
' If not, this won't work. Change this to reflect the name of YOUR
' table in your DataSet.
DataGrid1.DataSource = ds.Tables("mytable")
Dim ts As New DataGridTableStyle
ts.MappingName = "mytable" ' Change this to match the name of the table in your DataSet
DataGrid1.TableStyles.Add(ts)
ts.GridColumnStyles(0).Width = 100RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
It doesn't work because you reset the DataSource of the DataGrid, wiping out all the changes made to the TableStyles. Why are you adding all the Columns? You really don't need to unless your going to customize the look of them, which you're not doing in your code.
' I hope your DataSet actuall yhas a table in it called mytable.
' If not, this won't work. Change this to reflect the name of YOUR
' table in your DataSet.
DataGrid1.DataSource = ds.Tables("mytable")
Dim ts As New DataGridTableStyle
ts.MappingName = "mytable" ' Change this to match the name of the table in your DataSet
DataGrid1.TableStyles.Add(ts)
ts.GridColumnStyles(0).Width = 100RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
Finally I was able to resize it, Thanks for your Help and Support The codes are as Under for reference Dim mytable As DataTable mytable = New DataTable("MAIN") mytable.Columns.Add(New DataColumn("ContactPerson",GetType(String))) mytable.Columns.Add(New DataColumn("DESIGNATION",GetType(String))) mytable.Columns.Add(New DataColumn("PHONENO",GetType(String))) DataGrid1.DataSource = mytable Dim TS As New DataGridTableStyle TS.MappingName = "MAIN" DataGrid1.TableStyles.Add(TS) TS.GridColumnStyles.Item(1).Width = 100 TS.GridColumnStyles.Item(0).Width = 100 Thanks Again for your time :-D
-
Finally I was able to resize it, Thanks for your Help and Support The codes are as Under for reference Dim mytable As DataTable mytable = New DataTable("MAIN") mytable.Columns.Add(New DataColumn("ContactPerson",GetType(String))) mytable.Columns.Add(New DataColumn("DESIGNATION",GetType(String))) mytable.Columns.Add(New DataColumn("PHONENO",GetType(String))) DataGrid1.DataSource = mytable Dim TS As New DataGridTableStyle TS.MappingName = "MAIN" DataGrid1.TableStyles.Add(TS) TS.GridColumnStyles.Item(1).Width = 100 TS.GridColumnStyles.Item(0).Width = 100 Thanks Again for your time :-D
Pravin Hegde wrote:
The codes are as Under for reference
Precisely why you keep it in the forums! RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
Pravin Hegde wrote:
The codes are as Under for reference
Precisely why you keep it in the forums! RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome