Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create dataview from limited columns of dataset

Status
Not open for further replies.
Joined
Apr 11, 2002
Messages
193
Location
IN
Hi All,

I have a dataset of which datatable has 12 columns. As per users selection i want to display some columns in a datagrid. So i want to know if i can create a dataview which will contain some columns from the dataset like say 4 columns out of the 12. I dont want to go to the database everytime to fetch the results as the data is not changing frequently. If anyone has come across this situation then please help.

Thanks
Manish
 
I think you have three options here:

1) Create a new datatable with just the columns that you want
2) Keep the original dataset but hide some of the columns in the datagrid (e.g. set the width to 0)
3) Create an unbound datagrid and set the columns up yourself in code

If you go with option 2, I have just posted a sample this afternoon in thread855-1010525

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Hi,

Thanks for the reply. I want to create a datatable with just the fields that i want. Can you tell me how to do that.

Thanks
Manish
 
Yes - in the follwoing example I create a simple datatable and add 1 row - all you would need to do is add a new row to the DataTable for each record in your dataset (i.e. by looping through).

Code:
        Dim MyTable As New DataTable
        Dim myRow As DataRow

        MyTable.Columns.Add("Column1")
        MyTable.Columns.Add("Column2")

        myRow = MyTable.NewRow
        myRow.Item(0) = "Item 1"
        myRow.Item(1) = "Item 2"
        MyTable.Rows.Add(myRow)

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top