473,468 Members | 1,320 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

need algorithm to make sure only one datagrid row is checked

I have a column called "DefaultYN" in a resultset. It appears as a
boolColumn.

What I'd like to do is to ensure that only one row at a time can be
selected as the "Default" row. Unfortunately, I can't figure out

1. How to figure out that the checkbox has been checked
2. How to check the other rows to see if they're checked

Should I do this with the grid itself? Or with the underlying
datasource? The grid is bound to a datatable object.

Thanks for any info.

Brian Link, Minnesota Countertenor
- - - - - - - - - - - - - - - - -
"Mother, people only invite you to dinner for
three reasons: to sell you vitamins, to drug you
and take unpleasant snapshots, or to convert you
to their hideous farming religion."
Nov 20 '05 #1
10 1683
Cor
Hi Brian,

I think that if this was my problem I would save the place of the last
checked checkbox and unchecked that when there becomes another one.

I hope this helps?

Cor
Nov 20 '05 #2
Cor
Hi Brian,

I think that if this was my problem I would save the place of the last
checked checkbox and unchecked that when there becomes another one.

I hope this helps?

Cor
Nov 20 '05 #3
On Sun, 4 Apr 2004 08:46:07 +0200, "Cor" <no*@non.com> wrote:
Hi Brian,

I think that if this was my problem I would save the place of the last
checked checkbox and unchecked that when there becomes another one.

I hope this helps?

Cor


That's a good idea - but how to detect when a checkbox has been
checked?

BLink
Nov 20 '05 #4
On Sun, 4 Apr 2004 08:46:07 +0200, "Cor" <no*@non.com> wrote:
Hi Brian,

I think that if this was my problem I would save the place of the last
checked checkbox and unchecked that when there becomes another one.

I hope this helps?

Cor


That's a good idea - but how to detect when a checkbox has been
checked?

BLink
Nov 20 '05 #5
Hi Brian,

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to detect if a checked
box in the datagrid which is a boolean column has been checked.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

That is to say, the table will be checked, the value in the according
column will be true otherwise will be false.

I think you may try to use the Item property of datagrid.
Me.DataGrid1.Item(rows,cols).tostring()
[Note: the rows and cols are zero-based]

Also if you you have binding the datagrid onto a dataset or datatable, you
can retrieve the status from underlying datatable directly.

Please apply my suggestion above and let me know if it helps resolve your
problem.
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #6
Hi Brian,

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to detect if a checked
box in the datagrid which is a boolean column has been checked.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

That is to say, the table will be checked, the value in the according
column will be true otherwise will be false.

I think you may try to use the Item property of datagrid.
Me.DataGrid1.Item(rows,cols).tostring()
[Note: the rows and cols are zero-based]

Also if you you have binding the datagrid onto a dataset or datatable, you
can retrieve the status from underlying datatable directly.

Please apply my suggestion above and let me know if it helps resolve your
problem.
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #7
On Mon, 05 Apr 2004 06:47:51 GMT, v-******@online.microsoft.com
("Peter Huang") wrote:
Hi Brian,

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to detect if a checked
box in the datagrid which is a boolean column has been checked.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

That is to say, the table will be checked, the value in the according
column will be true otherwise will be false.

I think you may try to use the Item property of datagrid.
Me.DataGrid1.Item(rows,cols).tostring()
[Note: the rows and cols are zero-based]

Also if you you have binding the datagrid onto a dataset or datatable, you
can retrieve the status from underlying datatable directly.

Please apply my suggestion above and let me know if it helps resolve your
problem.
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


Thank you Peter - that answers part of my question.

The only other thing I need is a "Check" event on the datagrid. In
other words, where can I trap the click which checks or unchecks the
checkbox? This would be the event where I would evaluate its state,
and reset the other checkboxes accordingly.

Thanks

BLink
Nov 20 '05 #8
On Mon, 05 Apr 2004 06:47:51 GMT, v-******@online.microsoft.com
("Peter Huang") wrote:
Hi Brian,

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to detect if a checked
box in the datagrid which is a boolean column has been checked.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

That is to say, the table will be checked, the value in the according
column will be true otherwise will be false.

I think you may try to use the Item property of datagrid.
Me.DataGrid1.Item(rows,cols).tostring()
[Note: the rows and cols are zero-based]

Also if you you have binding the datagrid onto a dataset or datatable, you
can retrieve the status from underlying datatable directly.

Please apply my suggestion above and let me know if it helps resolve your
problem.
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


Thank you Peter - that answers part of my question.

The only other thing I need is a "Check" event on the datagrid. In
other words, where can I trap the click which checks or unchecks the
checkbox? This would be the event where I would evaluate its state,
and reset the other checkboxes accordingly.

Thanks

BLink
Nov 20 '05 #9
Hi Brian,

Based on my experience, I think there is no such event that will fired when
the value of the CheckedBox si changed.
Because when changed the value in the table, the RowChanged event of Table
will be fired until we move the focus onto another row, but this is not the
behavior we need here.

So I think we can try to handle the PositionChanged of CurrencyManager to
handle the checked state.

Here goes the code, you may have a try and let me know the result.

Dim WithEvents myCurrencyManager As CurrencyManager
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.SqlDataAdapter1.Fill(Me.DataSet11)
myCurrencyManager = CType(Me.DataGrid1.BindingContext(Me.DataSet11,
"TestTable"), CurrencyManager)
myCurrencyManager.Position = 0
Me.DataSet11.TestTable.Rows(0).Item("Checked") = True
End Sub

Private Sub myCurrencyManager_PositionChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles myCurrencyManager.PositionChanged
Try
Me.DataSet11.TestTable.Select("Checked = 1")(0).Item("Checked")
= False
Me.DataSet11.TestTable.Select("ID = " +
Me.DataGrid1(myCurrencyManager.Position, 0).ToString())(0).Item("Checked")
= True
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #10
Hi Brian,

Based on my experience, I think there is no such event that will fired when
the value of the CheckedBox si changed.
Because when changed the value in the table, the RowChanged event of Table
will be fired until we move the focus onto another row, but this is not the
behavior we need here.

So I think we can try to handle the PositionChanged of CurrencyManager to
handle the checked state.

Here goes the code, you may have a try and let me know the result.

Dim WithEvents myCurrencyManager As CurrencyManager
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.SqlDataAdapter1.Fill(Me.DataSet11)
myCurrencyManager = CType(Me.DataGrid1.BindingContext(Me.DataSet11,
"TestTable"), CurrencyManager)
myCurrencyManager.Position = 0
Me.DataSet11.TestTable.Rows(0).Item("Checked") = True
End Sub

Private Sub myCurrencyManager_PositionChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles myCurrencyManager.PositionChanged
Try
Me.DataSet11.TestTable.Select("Checked = 1")(0).Item("Checked")
= False
Me.DataSet11.TestTable.Select("ID = " +
Me.DataGrid1(myCurrencyManager.Position, 0).ToString())(0).Item("Checked")
= True
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Brian Link | last post by:
I have a column called "DefaultYN" in a resultset. It appears as a boolColumn. What I'd like to do is to ensure that only one row at a time can be selected as the "Default" row. Unfortunately, I...
8
by: Brian Link | last post by:
I have a column called "DefaultYN" in a resultset. It appears as a boolColumn. What I'd like to do is to ensure that only one row at a time can be selected as the "Default" row. Unfortunately, I...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.