943,991 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 13496
  • VB.NET RSS
Jul 19th, 2006
0

It's all about datagrid

Expand Post »
Hi,
A newbie to vb.net and I am trying to learn this datagrid. Here are my questions:
1. How can I populate a datagrid with selected column of a table without using a query.
2. How can I put a variable column width
3. Can someone show me a code for searching

Thanks in advance.. Pls. it's easier for me to understand if a code is possible.

Newvbguy
Similar Threads
Reputation Points: 13
Solved Threads: 3
Junior Poster in Training
NewVBguy is offline Offline
71 posts
since Mar 2005
Jul 25th, 2006
0

Re: It's all about datagrid

Hi

The way I populate a datagrid:

1- Create a dataset and a dataview.
2 - Get the database.
3 - Fill the dataset with the data from the database table.
4 - Set the dataview table to the dataset.
5 - Set the datasource of the datagrid to the dataview.
6 - Set the table style of the datagrid to show what you want to show.

- The column width you can set it up when setting the table style.
- If you want to filter the data, filter the dataview.

Hope it helps
Reputation Points: 23
Solved Threads: 10
Junior Poster
williamrojas78 is offline Offline
111 posts
since Jun 2005
Jul 26th, 2006
0

Re: It's all about datagrid

Oh Thanks. It seems simple but ok, I am interested with the table style. Is this something you can do at design level, in coding/run time. Do you have some codings pls. Thanks again.
newvbguy

Quote originally posted by williamrojas78 ...
Hi

The way I populate a datagrid:

1- Create a dataset and a dataview.
2 - Get the database.
3 - Fill the dataset with the data from the database table.
4 - Set the dataview table to the dataset.
5 - Set the datasource of the datagrid to the dataview.
6 - Set the table style of the datagrid to show what you want to show.

- The column width you can set it up when setting the table style.
- If you want to filter the data, filter the dataview.

Hope it helps
Reputation Points: 13
Solved Threads: 3
Junior Poster in Training
NewVBguy is offline Offline
71 posts
since Mar 2005
Jul 27th, 2006
0

Re: It's all about datagrid

yes sure, the tablestyles can be done with code:

VB.NET Syntax (Toggle Plain Text)
  1.  
  2. Me.DataGrid1.TableStyles.Clear()
  3.  
  4. 'Step 1: Create a DataGridTableStyle & set mappingname to table.
  5. Dim tableStyle As New DataGridTableStyle
  6. tableStyle.MappingName = "Table1"
  7.  
  8. Dim column As New DataGridTextBoxColumn
  9. column.ReadOnly = True
  10. column.MappingName = "ID"
  11. column.HeaderText = "Event_#"
  12. column.Width = 50
  13. column.Alignment = HorizontalAlignment.Center
  14. tableStyle.GridColumnStyles.Add(column)
  15.  
  16.  
  17. column = New DataGridTextBoxColumn
  18. column.ReadOnly = True
  19. column.MappingName = "Date"
  20. column.HeaderText = "Date_Time"
  21. column.Width = 110
  22. column.Alignment = HorizontalAlignment.Center
  23. tableStyle.GridColumnStyles.Add(column)
  24.  
  25. tableStyle.AlternatingBackColor = Color.Lavender
  26.  
  27. Me.DataGrid1.TableStyles.Add(tableStyle)

That will add two of the columns ("ID" and "Date") from Table1 to datagrid1. There you can specify the text you want to display, width, etc.

there is more information here if you wnat to go deeper:
http://msdn.microsoft.com/library/de...stDataGrid.asp
Reputation Points: 23
Solved Threads: 10
Junior Poster
williamrojas78 is offline Offline
111 posts
since Jun 2005
Jul 28th, 2006
0

Re: It's all about datagrid

Wow... That's all I need to do. Thanks.... HOW can you this at design time. Is it possible?.
Thanks again.

Newvbguy


Quote originally posted by williamrojas78 ...
yes sure, the tablestyles can be done with code:

VB.NET Syntax (Toggle Plain Text)
  1.  
  2. Me.DataGrid1.TableStyles.Clear()
  3.  
  4. 'Step 1: Create a DataGridTableStyle & set mappingname to table.
  5. Dim tableStyle As New DataGridTableStyle
  6. tableStyle.MappingName = "Table1"
  7.  
  8. Dim column As New DataGridTextBoxColumn
  9. column.ReadOnly = True
  10. column.MappingName = "ID"
  11. column.HeaderText = "Event_#"
  12. column.Width = 50
  13. column.Alignment = HorizontalAlignment.Center
  14. tableStyle.GridColumnStyles.Add(column)
  15.  
  16.  
  17. column = New DataGridTextBoxColumn
  18. column.ReadOnly = True
  19. column.MappingName = "Date"
  20. column.HeaderText = "Date_Time"
  21. column.Width = 110
  22. column.Alignment = HorizontalAlignment.Center
  23. tableStyle.GridColumnStyles.Add(column)
  24.  
  25. tableStyle.AlternatingBackColor = Color.Lavender
  26.  
  27. Me.DataGrid1.TableStyles.Add(tableStyle)

That will add two of the columns ("ID" and "Date") from Table1 to datagrid1. There you can specify the text you want to display, width, etc.

there is more information here if you wnat to go deeper:
http://msdn.microsoft.com/library/de...stDataGrid.asp
Reputation Points: 13
Solved Threads: 3
Junior Poster in Training
NewVBguy is offline Offline
71 posts
since Mar 2005
Jul 28th, 2006
0

Re: It's all about datagrid

That is the way you do it at designt time.
Is that what you mean? is what possible?
Reputation Points: 23
Solved Threads: 10
Junior Poster
williamrojas78 is offline Offline
111 posts
since Jun 2005
Jul 28th, 2006
0

Re: It's all about datagrid

oops sorry with my english. What I mean at design time is using the properties of the datagrid. to setup This is the time when you put a datagrid in a form. In other words setting up the table style without using a code.
thnx for the great help. now i am starting to grasp the power of vb.net

newvbguy


Quote originally posted by williamrojas78 ...
That is the way you do it at designt time.
Is that what you mean? is what possible?
Reputation Points: 13
Solved Threads: 3
Junior Poster in Training
NewVBguy is offline Offline
71 posts
since Mar 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Excel Warning - Responsing through the Excel Object
Next Thread in VB.NET Forum Timeline: anyone know how to use zedgraph in vb.net?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC