Datagridview + Checkbox + Button

  • (2 Pages)
  • +
  • 1
  • 2

24 Replies - 2424 Views - Last Post: 29 September 2011 - 02:18 AM Rate Topic: -----

#1 Ruchi22  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 118
  • Joined: 23-September 11

Datagridview + Checkbox + Button

Posted 28 September 2011 - 12:23 AM

Hello !!

I am making a simple windows application.
In one of the forms, I have buttons with various names and datagrid that displays the table.
Now, what i would like to do is if I click on a button titled "softwares", i want only those elements from my table whose type is Software, to be populated in the datagridview.
Not only that, I also want to have it accompanied with a checkbox so that, i can get the total selections in the textbox above !!
I am trying vb.net for the first time. Tried searching everywhere but nothnig seems to be working out.
Please help me. Any kind of help would be appreciated.

Thank You again, in advance !!

Is This A Good Question/Topic? 0
  • +

Replies To: Datagridview + Checkbox + Button

#2 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1817
  • View blog
  • Posts: 4,625
  • Joined: 14-March 10

Re: Datagridview + Checkbox + Button

Posted 28 September 2011 - 12:44 AM

Then just an sql query with WHERE clause. You then specify your required like normal sql queries
Was This Post Helpful? 0
  • +
  • -

#3 Ruchi22  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 118
  • Joined: 23-September 11

Re: Datagridview + Checkbox + Button

Posted 28 September 2011 - 01:24 AM

The queries i can manage.. Main concern is I am not being able to include checkbox in my datagridview.
I tried many snippets from various forums, not working.
I am using Ms Access and VS 2008. Data is dealt with, using OleDb command string..

Please help me. I haven't done any of this before..
Was This Post Helpful? 0
  • +
  • -

#4 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1817
  • View blog
  • Posts: 4,625
  • Joined: 14-March 10

Re: Datagridview + Checkbox + Button

Posted 28 September 2011 - 01:36 AM

So what do you want to do with those checkboxes? Where are they(mean inside grid view or outside)?
Was This Post Helpful? 0
  • +
  • -

#5 Ruchi22  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 118
  • Joined: 23-September 11

Re: Datagridview + Checkbox + Button

Posted 28 September 2011 - 02:01 AM

They are inside the gridview. I want to select multiple values of various items in the list and the count be displayed in the textbox..
Was This Post Helpful? 0
  • +
  • -

#6 Ruchi22  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 118
  • Joined: 23-September 11

Re: Datagridview + Checkbox + Button

Posted 28 September 2011 - 02:01 AM

They are inside the gridview. I want to select multiple values of various items in the list and the count be displayed in the textbox..
Was This Post Helpful? 0
  • +
  • -

#7 Ruchi22  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 118
  • Joined: 23-September 11

Re: Datagridview + Checkbox + Button

Posted 28 September 2011 - 02:07 AM

I mean, I want the checkbox inside the gridview, to enable multiple selection of various items..
Was This Post Helpful? 0
  • +
  • -

#8 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1817
  • View blog
  • Posts: 4,625
  • Joined: 14-March 10

Re: Datagridview + Checkbox + Button

Posted 28 September 2011 - 02:22 AM

So you have your data already in a grid view. After checking some of the checkboxes you can loop through all lines and count the number of checked ones like
Dim count As Integer = 0
        For i As Integer = 0 To DataGridView1.RowCount - 1
            If DataGridView1.Rows(i).Cells(0).Value Then ' column 0 is the one with checkboxes
                count += 1
            End If
        Next

Was This Post Helpful? 0
  • +
  • -

#9 Ruchi22  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 118
  • Joined: 23-September 11

Re: Datagridview + Checkbox + Button

Posted 28 September 2011 - 02:47 AM

no.. I am not getting the checkboxes in the gridview. That what i am trying to say !!

Sorry for keeping on troubling you.. :online2long:
Was This Post Helpful? 0
  • +
  • -

#10 Ruchi22  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 118
  • Joined: 23-September 11

Re: Datagridview + Checkbox + Button

Posted 28 September 2011 - 02:53 AM

Can i explain again ??

I need to have checkbox in my datagridview so that i can enable multiple multiple selection for various items.
When i click on 1 button, I want the relevant data from same table, be displayed.
As i have 7 buttons, I wish to populate a different list in the gridview, with checkboxes, each time i click on a particular button.

eg. I have bottuons of softwares, electronics etc.. my table name is Part no.

When i click on softwares, i want the grid to contain only those values having type software, in table partno. Same should go for every other button, 7 in all.

Hope this makes it a bit more clearer.

Thank You for Your patience..
:helpsmilie:
Was This Post Helpful? 0
  • +
  • -

#11 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1817
  • View blog
  • Posts: 4,625
  • Joined: 14-March 10

Re: Datagridview + Checkbox + Button

Posted 28 September 2011 - 03:33 AM

Can we see what you have done up to now? because first you said you have no problem with populating data, so I was expecting you have your data in the grid view already!

Let me make something clear:
- You can add a column with checkbox in design mode when you put your datagridview control. Just click it and right corner select add Column then select check box column...
- Then you can populate your data, if button1 is clicked just put a query to search for the appropriate data
Was This Post Helpful? 0
  • +
  • -

#12 Ruchi22  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 118
  • Joined: 23-September 11

Re: Datagridview + Checkbox + Button

Posted 28 September 2011 - 03:53 AM

Hey !! it worked..

Thank You so very much for your help..

Now can you plz just provide me a snippet of the steps to include while i want to display the items on button click ?

I mean, apart from query, what will i have to include ? M using it for the first time so completely naive about it..

Your help is appreciated.
Was This Post Helpful? 0
  • +
  • -

#13 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1817
  • View blog
  • Posts: 4,625
  • Joined: 14-March 10

Re: Datagridview + Checkbox + Button

Posted 28 September 2011 - 04:10 AM

If I am in button1 click event and I need only class A data my query will search for class = 'Class A'. this is all I can help unless you provide us with what you have tried and what problem you have with it. because I dont get where you have problem with. But if you post your code, then we can understand what are you trying to do.....
the change will just be the command text
Was This Post Helpful? 0
  • +
  • -

#14 Ruchi22  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 118
  • Joined: 23-September 11

Re: Datagridview + Checkbox + Button

Posted 29 September 2011 - 12:13 AM

Hello...

I have form having a button and a gridview. The gridview is ok and generates data.

But now, i want to populate only the data when i click on the button specified. Can anybody please help me with this ??

Here is my code :


    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click

        Try
            'MsgBox("Open")
            cn = New OleDbConnection("Provider=microsoft.jet.oledb.4.0;Data Source=E:\Project-Hemtech\HemDatabase1.mdb;")
            cn.Open()
            cmd = New OleDbCommand("select partname,partdesc,partnum,partqty from partno where type='Mechanical' ", cn)
            cmd.ExecuteNonQuery()

            MsgBox("Your Account Created Successfully ")

            Me.PartnoTableAdapter.Fill(Me.HemDatabase1DataSet1.partno)

        Catch myException As Exception

            MsgBox("No Record Inserted" + myException.ToString())

        Finally
            'MsgBox("Closing Connection")

            cn.Close()
        End Try



But this code gives entire data in the table named partno. I want only those records having type 'Mechanical'. Please help me out as there are 7 such buttons on the form.

Thank You so much !!

This post has been edited by stayscrisp: 29 September 2011 - 05:01 AM
Reason for edit:: Please use code tags!!

Was This Post Helpful? 0
  • +
  • -

#15 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1817
  • View blog
  • Posts: 4,625
  • Joined: 14-March 10

Re: Datagridview + Checkbox + Button

Posted 29 September 2011 - 12:36 AM

First use: :code:

Where did you add the data to the grid view?
You need to have:
DataGridView1.DataSource = dataSetName.Tables(0)

Then you will have your new data added to the grid view
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2