?
Solved

Small problem with DataGridView checkbox control - vb.net

Posted on 2007-09-28
22
Medium Priority
?
4,658 Views
Last Modified: 2013-11-26
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
Comment
Question by:nahumba
  • 11
  • 8
  • 3
22 Comments
 
LVL 21

Expert Comment

by:surajguptha
ID: 19982313
"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
 

Author Comment

by:nahumba
ID: 19982554
:-) 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
 
LVL 21

Expert Comment

by:surajguptha
ID: 19982796
Can you tell let me know what queries u used for both ?
0
Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

 

Author Comment

by:nahumba
ID: 19983327
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
 
LVL 21

Expert Comment

by:surajguptha
ID: 19983635
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
 

Author Comment

by:nahumba
ID: 19983724
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
 
LVL 21

Expert Comment

by:surajguptha
ID: 19983764
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
 

Author Comment

by:nahumba
ID: 19983778
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
 
LVL 21

Expert Comment

by:surajguptha
ID: 19983807
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
 

Author Comment

by:nahumba
ID: 19983844
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
 
LVL 21

Expert Comment

by:surajguptha
ID: 19984005
What exact query string are u using within the select statement??
0
 

Author Comment

by:nahumba
ID: 19984221
As I posted above:

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

Expert Comment

by:surajguptha
ID: 19984229
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
 

Author Comment

by:nahumba
ID: 19984243
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
 
LVL 21

Expert Comment

by:surajguptha
ID: 19984265
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
 

Author Comment

by:nahumba
ID: 19984291
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
 
LVL 34

Expert Comment

by:Sancler
ID: 19989483
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
 

Author Comment

by:nahumba
ID: 19991871
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
 
LVL 34

Expert Comment

by:Sancler
ID: 19992033
But that cannot be for a DataGridView.  What is the object that goes before the point?

Roger
0
 

Author Comment

by:nahumba
ID: 19992057
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
 
LVL 34

Accepted Solution

by:
Sancler earned 2000 total points
ID: 19992394
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
 

Author Comment

by:nahumba
ID: 19992590
Roger - it now works like a charm!


Thank you so much!!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question