Results 1 to 8 of 8

Thread: [02/03] Data Grid

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    24

    [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 =

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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).

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    24

    Re: [02/03] Data Grid

    wheres the asterisk? it no where on the grid.

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [02/03] Data Grid

    the asterisk is not visible in design mode, only when the app is running.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    24

    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?

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.     Dim dt As New DataTable
    3.  
    4.     dt.Columns.Add("ID", GetType(Integer))
    5.     dt.Columns.Add("Name", GetType(String))
    6.  
    7.     Dim dr As DataRow = dt.NewRow()
    8.  
    9.     dr("ID") = 1
    10.     dr("Name") = "Someone"
    11.     dt.Rows.Add(dr)
    12.  
    13.     dt.DefaultView.AllowDelete = False
    14.     dt.DefaultView.AllowNew = False
    15.  
    16.     Me.DataGrid1.DataSource = dt
    17. End Sub
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width