Results 1 to 10 of 10

Thread: listview or datagrid? [RESOLVED]

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    listview or datagrid? [RESOLVED]

    I will be getting information from a database and displaying it on a form. I am going to allow users to sort each row by clicking on each columns' header. I want grid lines (listview) but I don't know if I can do any kind of sorting with a listview control.

    One other feature I'd like to incorporate is to be able to colorize individual rows depending on certain conditions.

    Can anyone give me suggestions on what control to use or a combination of?
    Last edited by Andy; Feb 11th, 2004 at 09:48 PM.

  2. #2
    Member
    Join Date
    Dec 2003
    Posts
    43
    Id go with the listview. It has sorting in Acending or Decending order. Column headers. Here is a quick code snippet on highlighting every other line of text a different color.
    VB Code:
    1. Dim item As ListViewItem
    2.                   For Each item In lvwEmployeeInfo.Items
    3.                 If (item.Index Mod 2) = 0 Then
    4.                     item.BackColor = Color.Gray
    5.                 Else
    6.                     item.BackColor = Color.White
    7.  
    8.  
    9.                 End If
    10.  
    11.             Next

  3. #3
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Binding Listview to data source is not as easy as Datagrid. And if you go for datagrid you can easily change the back color of the row depending on a condition.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    ah, excellent arguments for both controls, fellas. I'll just have to try both. I was truly thinking that the datagrid was the way to go but I REALLY want to be able to sort by headers. Hmmm.....have to weigh my options (or write lots of code)

  5. #5
    Member
    Join Date
    Dec 2003
    Posts
    43
    Personally i think databinding in .net sucks. If you want ease of use and flexibility i would do it unbound. Its much more logical and your not confined to the "bound" system. Databinding manager is ridiculous.

  6. #6
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Originally posted by AFterlife
    Personally i think databinding in .net sucks. If you want ease of use and flexibility i would do it unbound. Its much more logical and your not confined to the "bound" system. Databinding manager is ridiculous.
    I basically accept the idea that binding suck, but that is mainly for simple binding and would you please tell me how you gonna use datagrid if you are not going to bind it to a datasource?
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  7. #7
    Member
    Join Date
    Dec 2003
    Posts
    43
    I just meant not to do it that way. No biggie.Because i dont like to be forced to do something,in someway, that ill possibly pay for later. Which is why i stick with things that are "unbound".

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    I'm not sure what you mean by "unbound" either. I am new to databases and the ado thing. I just discovered that the datagrid DOES have seperated lines ! How can I adjust the background color of individual records?

  9. #9
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  10. #10
    New Member
    Join Date
    Jan 2004
    Location
    Italia
    Posts
    10
    After dropping an instance of the datagrid on the form, right-click it and choose 'Auto Format'. An auto format dialog box will appear and you can choose from predetermined layouts in the listbox on the left hand side (you will see a preview of the layout on the right hand side).

    You can, thereafter if you wish, view the code generated under:

    #Region " Windows Form Designer generated code "

    You will see code like:

    Me.DataGrid1.AlternatingBackColor = System.Drawing.Color.LightGray
    Me.DataGrid1.BackColor = System.Drawing.Color.DarkGray

    I personally perfer the listview if the data is read only and unbound.

    In my words (a short explanation), unbound means that you must populate controls (for example from a dataview, dataset, xml file, etc.) on the form through code that you generate. As opposed to 'binding':

    textbox1.DataBindings.Add("Text", dataview1, dataview1.Table.Columns(1).ColumnName)

    I personally use a combination of both. The 'BindingManagerBase' object to determine where I'm at, and I populate the controls myself. But I am new to the .net architecture, so I may be making a mess of things.
    DaDragon

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