Results 1 to 4 of 4

Thread: By name and not By index

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    194

    By name and not By index

    when I want to change parameters in column I have to write the index of the column and not the name

    for example
    this code work good


    Dim dtchild As DataTable = New DataTable
    dtchild.Columns.Add("cID", GetType(System.Int32))
    dtfather.Columns(1).Unique = True

    but here I get error


    Dim dtchild As DataTable = New DataTable
    dtchild.Columns.Add("cID", GetType(System.Int32))
    dtfather.Columns("cID").Unique = True

    the Same problem with dataTable

    this code is OK

    For Each ro In ds.Tables(0).Rows

    and here I got error

    For Each ro In ds.Tables("dtfather").Rows

    how can I use the name and not the indexes?

    thanks alot

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    194

    and another question

    in access I can lock the combobox

    me.combo1.locked = true

    in vb.net there is no this option
    I can just to Enabled but then its change the color and its not good for me

    Is there a way to locked the combo and not by Enabled?

    thanks again

  3. #3
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: By name and not By index

    Quote Originally Posted by 24sharon
    when I want to change parameters in column I have to write the index of the column and not the name

    for example
    this code work good


    Dim dtchild As DataTable = New DataTable
    dtchild.Columns.Add("cID", GetType(System.Int32))
    dtfather.Columns(1).Unique = True

    but here I get error


    Dim dtchild As DataTable = New DataTable
    dtchild.Columns.Add("cID", GetType(System.Int32))
    dtfather.Columns("cID").Unique = True

    the Same problem with dataTable

    this code is OK

    For Each ro In ds.Tables(0).Rows

    and here I got error

    For Each ro In ds.Tables("dtfather").Rows

    how can I use the name and not the indexes?

    thanks alot

    dunno what happend to your machine but it works in my machine

    VB Code:
    1. Dim ds As New DataSet()
    2.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    3.         values()
    4.         Me.DataGrid1.DataSource = ds.Tables("dt")
    5.         Dim r As DataRow
    6.         For Each r In ds.Tables("dt").Rows
    7.             MessageBox.Show(r(0).ToString)
    8.         Next
    9.     End Sub
    10.  
    11. Sub values()
    12.         Dim s() As String = {"awe3cg", "waheh", "askdjf", "lkajsd"}
    13.         ds.Tables.Add("dt")
    14.         ds.Tables("dt").Columns.Add("name")
    15.         ds.Tables("dt").Columns("name").Unique = True
    16.         Dim i As Integer
    17.         For i = 0 To UBound(s)
    18.             Dim d As DataRow = ds.Tables("dt").NewRow
    19.             d(0) = s(i)
    20.             ds.Tables("dt").Rows.Add(d)
    21.         Next
    22.     End Sub

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    194

    Re: By name and not By index

    mar_zim

    Thanks!


    did someone know the replay to my second question?

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