|
-
Jun 1st, 2006, 01:44 PM
#1
Thread Starter
Junior Member
[02/03] Data Grid
how do i add text to the data grid and stuff?
datagrid1.text = does not work???
the only thing that works is datagrid1.captiontext =
-
Jun 1st, 2006, 04:02 PM
#2
Re: [02/03] Data Grid
You can add text and 'stuff' to your datagrids by entering them in the row at the bottom of the grid marked with an asterisk.
Unless you're looking to bind your datagrid to some data from a database, in which case you should set the datasource property of the datagrid to a dataset (which you have filled up).
-
Jun 1st, 2006, 05:40 PM
#3
Thread Starter
Junior Member
Re: [02/03] Data Grid
wheres the asterisk? it no where on the grid.
-
Jun 1st, 2006, 05:42 PM
#4
Re: [02/03] Data Grid
the asterisk is not visible in design mode, only when the app is running.
-
Jun 1st, 2006, 05:53 PM
#5
Re: [02/03] Data Grid
The DataGrid works best, i.e. easiest for you and your code, when it is bound to a DataTable. If you want to see the effects of this then add a DataSet to your form, add a DataTable to it, add some columns to that, then set the DataSource and DataMember of the DataGrid. You'll see the columns of the DataTable appear in the DataGrid. You can then populate that DataTable in the form constructor or Load event handler and when you run your app that data will be displayed in the DataGrid. All the data binding can be achieved in code also, but if you know the table schema it is easier in the designer. Having said that, I'm sure that mendhak will agree with me that you should understand what's happeneing when you bind a data source to a control.
-
Jun 1st, 2006, 07:05 PM
#6
Thread Starter
Junior Member
Re: [02/03] Data Grid
1. How do i make it so there is only 1 row?
2. How do i set the data in the columns?
-
Jun 1st, 2006, 07:39 PM
#7
Re: [02/03] Data Grid
Are you using a DataTable like I suggested? If so then you can bind the grid directly to the table by assigning the DataTable to the DataSource rather than the DataSet to the DataSource and the name of the DataTable to the DataMember. You can then set the DefaultView.AllowNew and DefaultView.AllowDelete properties of the DataTable to False. If you then add one row to the table, when the grid is displayed the user will see one row. The row will be editable but they will not be able to add another row or delete the existing row. For a simple demonstartion of what I'm talking about, create a new project and add a DataGrid to the form. Double-click the the form to create a Load event handler and add this code:
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
dt.Columns.Add("ID", GetType(Integer))
dt.Columns.Add("Name", GetType(String))
Dim dr As DataRow = dt.NewRow()
dr("ID") = 1
dr("Name") = "Someone"
dt.Rows.Add(dr)
dt.DefaultView.AllowDelete = False
dt.DefaultView.AllowNew = False
Me.DataGrid1.DataSource = dt
End Sub
-
Jun 1st, 2006, 08:03 PM
#8
Re: [02/03] Data Grid
Having said all that, having a DataGrid for just a single row, if that's all there will ever be, is probably a bit pointless. I'd be more inclined to use separate controls for each value. I think that will create a more attractive and more usable interface for that small amount of data.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|