• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4701
  • Last Modified:

Small problem with DataGridView checkbox control - vb.net

Dear experts!

I have a DataGridView control on my form which is bind to a local database.
The grid contains a checkbox column.

The application allows the user to perform some queries on the datagridview control in order to "filter" data.

The problem is, that the checkboxes are shown as checked only when the datagridview shows the whole table from the database (ie, no select statements). If the user performs a query on the table, then even if the checkboxes are checked - they won't look like they are indeed checked.

Why is this happening and how can this be solved?

Thanks in advance!
0
nahumba
Asked:
nahumba
  • 11
  • 8
  • 3
1 Solution
 
surajgupthaCommented:
"then even if the checkboxes are checked - they won't look like they are indeed checked."

I cannot understand what you mean by the above statement.Can you explain this?
0
 
nahumbaAuthor Commented:
:-) Sorry:

The datagrid contains data from a local .mdb file.

Everything is OK when the whole data is shown inside the table.

BUT,
In I case I want to perform a 'Select' on the table, then all check boxes apears as "unchecked".
So basically - I am able to see the checkboxes's real status only when the whole data is shown - without any 'Select' statements.

Thanks!
0
 
surajgupthaCommented:
Can you tell let me know what queries u used for both ?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
nahumbaAuthor Commented:
Hi,
the grid contains 6 columns, the user may perform a Select based on two column names. The 'Select' statement does not include the 6st column which is the checkbox column.
0
 
surajgupthaCommented:
I am still not very clear but if you are not including the 6th column which is the checkbox column, how will the grid display the checks without the data?
0
 
nahumbaAuthor Commented:
Here's a quick example:

-------------------------------------------------------------------------------------------
USING THE DEFAULT SELECT STATEMENT (ALL COLUMNS ARE INCLUDED)
-------------------------------------------------------------------------------------------

Column (1)        Column(2)       Column(3)    Column(4)    Column (5 - Check box column)
======================================================================
some vaule        another vaule                                           Checked <------------
another value          .......                                                    Checked
and another value   .......                                                     Not Checked

---------------------------------------------------------------------------------------
SELECT ("COLUMN (1) = 'some value' AND Column (2) = 'another value'
---------------------------------------------------------------------------------------
Result:
--------

Column (1)        Column(2)       Column(3)    Column(4)    Column (5 - Check box column)
======================================================================
some vaule        another vaule                                           NOT CHECKED <-------
                                                                                            -----------------

**************************************************
Notice the check box status, when ALL data is shown, the check box is correct. When using the Select statement (see figure 2) - check box appears as unchecked.

Thanks!
0
 
surajgupthaCommented:
1) Is column 5 a Char value or a kind of Bool value?
2) Are all these columns unbound columns?
3) FOr case 1) manually key in all the columns instead of keying in *
0
 
nahumbaAuthor Commented:
Hi surajguptha,

Yes, column 5 is a Char value ("Yes" - checked, "No" - unchecked).
Can you be more specific about section number (3)?

Will converting column 5 into a bool value make things easier? If yes, how can this be done?

Thanks again!
0
 
surajgupthaCommented:
3)

If you did a select * from employee it would internally convert it into select col1,col2,col3,col4 from the database. where col1,col2,col3.col4 are all the columns of the table

Can you try doing that? Can you convert your * and replace it with all the actual columns?
0
 
nahumbaAuthor Commented:
I know how to do this with a "regular" sql statement,
but since I'm using the .Select() method of the datagridview control, I don't know how to achieve the same results as I would with my original select query.

Can you post an example of such query?

0
 
surajgupthaCommented:
What exact query string are u using within the select statement??
0
 
nahumbaAuthor Commented:
As I posted above:

SELECT ("COLUMN (1) = 'some value' AND Column (2) = 'another value'
0
 
surajgupthaCommented:
You seem to be doing everything right. I am not sure why this happens for one and not for the other. ITs silly but have u checked if all the values that get filtered actually dont have column 5 as Y or True ??
0
 
nahumbaAuthor Commented:
Well,
I don't need to check them - or don't want to :-)

I just want them to show their real status after the select command, regardless of the filtered data.
0
 
surajgupthaCommented:
Its difficult to be understand over here without the code and stuff so can you try one more thing
Can you put in some silly select condition like 1=1 or a condition that would select all the items ?? But a select filter should be present. Lets see if it still removes the checks?
0
 
nahumbaAuthor Commented:
Yes, I'll try that soon - I'll post back and let you know later on, I must leave now.

And thanks again!
Your help is really appreciated!
0
 
SanclerCommented:
nahumba

In post #19983844 you said "... since I'm using the .Select() method of the datagridview control ...".  The datagridview doesn't have a .Select method of this sort.  Its .Select method is inherited from Control, and is only concerned with selecting a sub control, not a record or records, within the main control.

Also, whatever method it is you are actually using, the expression

SELECT ("COLUMN (1) = 'some value' AND Column (2) = 'another value'

that you included in posts #19983724 and #19984221 would fail.  The opening bracket and double quotes are not closed.

So can you please post the code that you are actually using?

Roger
0
 
nahumbaAuthor Commented:
Hi Roger,
Here's the correct query:
.SELECT ("COLUMN (1) = 'some value' AND Column (2) = 'another value'")

That's the method I'm using - the only difference are the values and column names - but that's the syntax.

Thank you!!!!
0
 
SanclerCommented:
But that cannot be for a DataGridView.  What is the object that goes before the point?

Roger
0
 
nahumbaAuthor Commented:
Oh sorry,
Here's how I do it:

Dim MainSelect As DataRow()
MainSelect = Me.DataSet1.Table1.SELECT ("COLUMN (1) = 'some value' AND Column (2) = 'another value'")
DataGridView2.DataSource = MainSelect
0
 
SanclerCommented:
You're using the wrong object.  Try this instead

Dim MainSelect As New DataView(Me.DataSet1.Table1)
MainSelect.RowFilter = "COLUMN (1) = 'some value' AND Column (2) = 'another value'"
DataGridView2.DataSource = MainSelect

Roger
0
 
nahumbaAuthor Commented:
Roger - it now works like a charm!


Thank you so much!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 11
  • 8
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now