Column Dynamic Behavior

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

Hi, I have a column question defined as below:
*environment: C#, ADO.NET, window application
*after a DataSet is filled.
*its table is rendered in some control, ie ListBox,DataGrid
*if I want to make one column disappear
* or to change the order of the columns
* still using the previous filled DataSet
Is it possible to do so? Please advice. Thanks.
Peter
 
Hi Peter,

One way would be to shuffle columns in DataTable by removing them and adding
in desired order.
You won't be able to hide the column, afaik.
Maybe threra are better methods, though.
However, the visual components should support the reordering - you might
check into more sophisticated 3rd party...
 
Hi Peter

Its possible to hide a column in a datagrid. You can do this via the
Datagridtablestyle object in the datagrid, beneath is an example
Dim tblStyle As New DataGridTableStyle()

With tblStyle

..MappingName = "pricelist" -> mapping to the dataset name

..BackColor = System.Drawing.Color.White

..ForeColor = System.Drawing.Color.DarkSlateBlue

..GridLineColor = System.Drawing.Color.MediumSlateBlue

..HeaderBackColor = System.Drawing.Color.Lavender

..HeaderForeColor = System.Drawing.Color.MediumSlateBlue

..AlternatingBackColor = Color.LightGray

..RowHeaderWidth = 10

Dim Productcol As New DataGridTextBoxColumn()

With Productcol

..HeaderText = "Produkt"

..MappingName = "ProductName"

..Width = 300

End With

Dim Brutocol As New DataGridTextBoxColumn()

With Brutocol

..MappingName = "Recommended_price"

..NullText = "0"

..HeaderText = "Richtprijs"

..Alignment = HorizontalAlignment.Right

..Width = 80

..Format = "C"

End With

' Hide netto prices by default

With Nettocol

..MappingName = "Lowest_price"

..NullText = "0"

..HeaderText = ""

..Alignment = HorizontalAlignment.Right

..Width = 0

..Format = "C"

End With

Dim Commentarycol As New DataGridTextBoxColumn()

With Commentarycol

..MappingName = "Extra"

..NullText = ""

..HeaderText = "Opmerkingen"

..Width = 500

End With

tblStyle.GridColumnStyles.Add(Productcol)

tblStyle.GridColumnStyles.Add(Brutocol)

tblStyle.GridColumnStyles.Add(Nettocol)

tblStyle.GridColumnStyles.Add(Commentarycol)

End With

Every column you want to use has to be defined as a datagridcolumn. Now,
set the width to 0 instead of 500 for example, and the column wont be
visible anymore
 
Back
Top