Results 1 to 7 of 7

Thread: [RESOLVED] [02/03] Datagrid column Count return 0 always ...

  1. #1

    Thread Starter
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    Resolved [RESOLVED] [02/03] Datagrid column Count return 0 always ...

    Hi all,

    I have bind datagrid dynamically through coding .. it display 2 columns at runtime.

    Now i want to make the First column align Right while second to Left.

    So i tried to solve it using
    VB Code:
    1. DataGrid.Columns(0).Style.HorizontalAlignment = .....Right
    But the problem i face is that when i use

    VB Code:
    1. Datagrid1.Datasource = ds.Tables(0)
    2. 'Response.Write(Datagrid.Columns.Count)
    3. Datagrid1.Databinding()
    4. Response.Write(Datagrid.Columns.Count)

    it always gives 0

    I know this problem is due to dynamic column binding. But don't know how to solve it..

    Help me URGENT..
    I am using .NET 2010 with Windows 7

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [02/03] Datagrid column Count return 0 always ...

    Could you just get the count off of your ds?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    Re: [02/03] Datagrid column Count return 0 always ...

    ok to be more specific..

    VB Code:
    1. DataGrid1.DataSource = ds.Tables(1)
    2.  
    3. Response.Write(ds.Tables(1).Columns.Count) ' This Return 2
    4. Response.Write(DataGrid1.Columns.Count)' This Return 0
    5.  
    6.  
    7. DataGrid1.DataBind()
    8.  
    9. Response.Write(ds.Tables(1).Columns.Count) ' This Return 2
    10. Response.Write(DataGrid1.Columns.Count) '' This Return 0

    I am using Dynamic binding..
    I am using .NET 2010 with Windows 7

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [02/03] Datagrid column Count return 0 always ...

    But as I was saying its easier to just reference your datasets column collection. The columns collection is never used when dynamically generated.

    Automatically generated columns are not added to the Columns collection.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    Re: [02/03] Datagrid column Count return 0 always ...

    ** Bump **

    Ok i want this ..

    1. I want to bind datagrid dynamically
    2. After then I want to right align first column of datagrid

    Can u tell me how's that possible ?
    I am using .NET 2010 with Windows 7

  6. #6

    Thread Starter
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    Re: [02/03] Datagrid column Count return 0 always ...

    I understood what Rob want to explain and I did my best to solve this. But Could't do anything to solve this.

    I am currently using alternative method from backend.. But still desparate to know the solution.

    Come on guys i have to solve this during this 2 hours. plz help me..
    I am using .NET 2010 with Windows 7

  7. #7

    Thread Starter
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    Re: [02/03] Datagrid column Count return 0 always ...

    Sorry couldn't think of this easy method earlier..

    VB Code:
    1. DataGrid1.AutoGenerateColumns = False
    2.         DataGrid1.DataSource = ds.Tables(1)
    3.         Dim bCol As New BoundColumn
    4.         bCol.DataField = "FieldValue"
    5.         bCol.ItemStyle.HorizontalAlign = HorizontalAlign.Right
    6.         DataGrid1.Columns.Add(bCol)
    7.         DataGrid1.DataBind()

    Hurrayieeeeee........
    I am using .NET 2010 with Windows 7

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