Results 1 to 9 of 9

Thread: How to dislay data in table in CF20 (DataGrid or ListView) with Column Width

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2002
    Posts
    352

    How to dislay data in table in CF20 (DataGrid or ListView) with Column Width

    As far as I can see the DataGridView is not available in CF20, but DataGrid is. I need to display several records in a table. I have no problem loading the records into a DataGrid control, but cannot find a way to fix the column width in the DataGrid columns.

    How do I change the width of the columns to preset values or the largest value in the column? Should I do it as a DataTable first, or some other method.

    Thanks.
    Last edited by easymoney; Apr 23rd, 2007 at 07:25 AM.

  2. #2
    Member
    Join Date
    Mar 2007
    Posts
    55

    Re: How to dislay data in table in CF20 (DataGrid) with Column Width

    Code:
    lstMat.View = View.Details
    lstMat.Columns.Add("ID", 80, HorizontalAlignment.Left)
    80 = width.
    This what you been looking for ?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2002
    Posts
    352

    Re: How to dislay data in table in CF20 (DataGrid) with Column Width

    Ok. I could use a listview. Here is some code I tried using with a ListView:

    Code:
        Public Sub FillListView(ByRef MyListView As ListView, _
                                                             ByRef myData As SqlCeDataReader)
            Dim lvwColumn As ColumnHeader
            Dim itmListItem As ListViewItem
    
            Dim strTest As String
            Dim intLength As Integer
    
            Dim shtCntr As Short
    
            Do While myData.Read
                itmListItem = New ListViewItem()
    
                'strTest = IIf(myData.IsDBNull(0), "", myData.GetString(0))
                If myData.IsDBNull(0) Then
                    strTest = ""
                Else
    
                End If
    
                itmListItem.Text = strTest
    
                For shtCntr = 0 To myData.FieldCount() - 1
    
                    If myData.IsDBNull(shtCntr) Then
                        itmListItem.SubItems.Add("")
                    Else
                        If shtCntr = 0 Then
    
                        Else
                            itmListItem.SubItems.Add(myData.GetString(shtCntr))
                        End If
    
                    End If
                Next shtCntr
    
                MyListView.Items.Add(itmListItem)
            Loop
    It fills the list view with the 3 columns I have already added prior to loading the Sql datal, but the Column 0 (primary key in table) either generates an InvalidCast error or leaves the first column blank.

    Any idea why?

  4. #4
    Member
    Join Date
    Mar 2007
    Posts
    55

    Re: How to dislay data in table in CF20 (DataGrid or ListView) with Column Width

    Im doing something like this for it to work
    .
    Code:
     Private Sub FORM1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
            
            lstMat.View = View.Details
            lstMat.Columns.Add("ID", 80, HorizontalAlignment.Left)
            lstMat.Columns.Add("name", 80, HorizontalAlignment.Left)
    
    
    end sub
    
     another sub 
    
    connection("select * from materials where supplierID = " & DirectCast(cmbLeverancier.SelectedItem,supplier).supplierID)
                
    tmpReader = sqlCmd.ExecuteReader
                While tmpReader.Read
                    Dim description As String = tmpReader("articleID")
                    Dim item As ListViewItem = New ListViewItem(description)
                    Dim strtext As String
                    strtext = tmpReader("ArtikelID")
                    item.SubItems.Add(strtext)
                    strtext = tmpReader("description")
                    item.SubItems.Add(strtext)
                    lstMat.Items.Add(item)
                End While
    its a bit sloppy i guess but it does work.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2002
    Posts
    352

    Re: How to dislay data in table in CF20 (DataGrid or ListView) with Column Width

    I will look into this again this evening. Time for some rest.

  6. #6
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Re: How to dislay data in table in CF20 (DataGrid or ListView) with Column Width

    . .
    Last edited by Strider; Apr 24th, 2007 at 05:28 PM.
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

  7. #7
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Re: How to dislay data in table in CF20 (DataGrid or ListView) with Column Width

    what line is it throwing the exception.
    also if any of the fields contains a null value it will throw an exception when you try to assign it.
    so you will need to create a function to check if the reader value is null see below

    Code:
    Private Sub CheckIfNullString(ByVal p_reader As SqlCeReader, ByVal p_colname As String) As String
    Dim l_value as String = ""
    If Not p_reader(p_colname) IsDBNull then
        l_value = p_reader.getString(p_colName)
    End If
    return l_value
    End Sub
    or else use
    Code:
    If Not tmpReader("ArtikelID") IsDBNull Then
        strtext = tmpReader("description")
    End If
    Last edited by Strider; Apr 24th, 2007 at 05:22 PM.
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

  8. #8
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Re: How to dislay data in table in CF20 (DataGrid or ListView) with Column Width

    Quote Originally Posted by easymoney
    As far as I can see the DataGridView is not available in CF20, but DataGrid is. I need to display several records in a table. I have no problem loading the records into a DataGrid control, but cannot find a way to fix the column width in the DataGrid columns.

    How do I change the width of the columns to preset values or the largest value in the column? Should I do it as a DataTable first, or some other method.

    Thanks.

    for a datagrid you need to use the datagridtablestyles to set width and titles

    sample here: http://www.codeproject.com/csharp/cu...select=1075940
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2002
    Posts
    352

    Re: How to dislay data in table in CF20 (DataGrid or ListView) with Column Width

    Quote Originally Posted by Strider
    for a datagrid you need to use the datagridtablestyles to set width and titles

    sample here: http://www.codeproject.com/csharp/cu...select=1075940
    Yea, good example. I have some code that works well for that task, just didn't include it to simply things. The column format fine, just having trouble getting the primary key loaded into cell into the first colum.

    The code above works with bug, its just sloppy handling Integer or Null values. I just need to clean up the routine above and make it al little more efficent. Right idea, just bad handling.

    I will see if I can clean it a bit and then add the column handler back in once it fixed.

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