Results 1 to 15 of 15

Thread: [2005] DataGridView

  1. #1

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Question [2005] DataGridView

    Hi all
    how to select checked row of the DataGridView view without loop

  2. #2
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: [2005] DataGridView

    Quote Originally Posted by shakti5385
    Hi all
    how to select checked row of the DataGridView view without loop
    Hi,

    Here's an example how to select a row:

    Code:
    Datagridview1.Rows(index).Selected = True
    Hope it helps,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  3. #3

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: [2005] DataGridView

    NO in a DataGridView there is 5 rows. and the 3 rows are checked by me ( there is checkbox column on the DataGridView )
    I want to count that three row without using any loop.
    Thanks

  4. #4

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: [2005] DataGridView

    Any One has Any Idea
    Thanks

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

    Re: [2005] DataGridView

    As I have suggested to you and others many times, if you have data bound to a grid then use the data source, not the grid, to manipulate the data:
    vb.net Code:
    1. Dim trueRowCount As Integer = CInt(DataTable.Compute("COUNT(ColumnName)", "ColumnName = True"))
    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
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: [2005] DataGridView

    If I am not wrong then your code on the datatable not on the DataGridView?

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

    Re: [2005] DataGridView

    What gave it away?
    Dim trueRowCount As Integer = CInt(DataTable.Compute("COUNT(ColumnName)", "ColumnName = True"))
    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

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: [2005] DataGridView

    But I am asking for the DataGridView.

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

    Re: [2005] DataGridView

    Where does the data in the grid come from? A bound DataTable?
    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

  10. #10

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: [2005] DataGridView

    VB.NET Code:
    1. myGrid.DataSource=DataTable

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

    Re: [2005] DataGridView

    If you DataTable is bound to your DataGridView then the data in each is the same, correct? So then the number of rows in the DataTable with a particular value in a particular column is going to be the same as the number of rows in the DataGridView with that same particular value in the corresponding column. Isn't that the point of data-binding: the data in the control and the source beahve as one?
    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

  12. #12

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: [2005] DataGridView

    But when you click on the DataGridView cell then how we can know that the datatable column is also checked?

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

    Re: [2005] DataGridView

    Well, I can't see why you would want to count the number of rows in a grid containing a certain value if there was still an edit pending, and having a pending edit is the only way that the data in the grid will not be in sync with the data in the DataTable.

    Anyway, your question was how to count the rows without a loop. I've shown you how to do that using the bound DataTable. If you want to do it from the grid itself then you can't do it without a loop. You'd just have to check every row and test the value in that column.
    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

  14. #14

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: [2005] DataGridView

    Yesterday you was saying to use the Binding source Class so is it necessary to use binding source is the place of datatable?

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

    Re: [2005] DataGridView

    You do not use a BindingSource in place of a DataTable... anywhere. A BindingSource does not contain any data of its own. A BindingSource is merely an object through which data passes and is viewed to make data-binding easier. When you populate a DataTable you bind it to a BindingSource, then bind the BindingSource to your control(s), e.g. a DataGridView.

    I have shown you how to do what you've asked for. If you were supposed to use a BindingSource then my code would have included a BindingSource. It doesn't. Use the DataTable.Compute method, exactly as I have shown.
    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