datagridview and checkbox column

Hi
I'm building windows form using C# and framework 2.0.

I have  got one gridview form with two columns (one is text, another is 
checkbox column).

I'm trying to write a code so user can select only one checkbox at a time, 
if he tries to select another checkbox from other row, it should prompt 
error msg if already one checkbox is selected.

In short, at any time, only one row checkbox should be allowed to be 
selected.

I tried to use CurrentCellDirtyStateChanged and counted check value but i 
couldn't cancel changes using EndEdit or CancelEdit if selected checkbox are 
more than one.

Can anyone help on this?
It would be really appreciated if someone can post dummy code.

Thanks in advance...


0
Bhavin
11/16/2009 4:39:35 AM
dotnet.languages.csharp 1931 articles. 0 followers. Follow

2 Replies
1897 Views

Similar Articles

[PageSpeed] 52

Hi,

You can use datagridview's cellClick event.

Search the checkbox, check it, and deselect all other cehckboxes by
looping all the items of datagridview.

 Private Sub dgvKeywordSearch_CellClick(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles
dgvKeywordSearch.CellClick


      Dim checkBoxCell As DataGridViewCheckBoxCell =
TryCast(dgvKeywordSearch.Rows(e.RowIndex).Cells(0),
DataGridViewCheckBoxCell)

  If checkBoxCell IsNot Nothing Then

                If checkBoxCell.ValueType.Equals(GetType(Boolean)) Then

    Dim checked As Boolean = CType(checkBoxCell.Value, Boolean)

   If checkBoxCell.Value = True Then
     For i = 0 To dgvKeywordSearch.Rows.Count - 1
       Dim chk As DataGridViewCheckBoxCell =
TryCast(dgvKeywordSearch.Rows(i).Cells(0), DataGridViewCheckBoxCell)
   chk.Value = False
        Next

     End If
  End If

Hope this will help you !!

Regards,
Mansi Shah

*** Sent via Developersdex http://www.developersdex.com ***
-1
Mansi
11/16/2009 8:38:17 AM
Thanks Mansi

Your solution did work for me.
Cheers

"Mansi Shah" <mansi@devdex.com> wrote in message 
news:%23E4FmgpZKHA.5620@TK2MSFTNGP06.phx.gbl...
> Hi,
>
> You can use datagridview's cellClick event.
>
> Search the checkbox, check it, and deselect all other cehckboxes by
> looping all the items of datagridview.
>
> Private Sub dgvKeywordSearch_CellClick(ByVal sender As System.Object,
> ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles
> dgvKeywordSearch.CellClick
>
>
>      Dim checkBoxCell As DataGridViewCheckBoxCell =
> TryCast(dgvKeywordSearch.Rows(e.RowIndex).Cells(0),
> DataGridViewCheckBoxCell)
>
>  If checkBoxCell IsNot Nothing Then
>
>                If checkBoxCell.ValueType.Equals(GetType(Boolean)) Then
>
>    Dim checked As Boolean = CType(checkBoxCell.Value, Boolean)
>
>   If checkBoxCell.Value = True Then
>     For i = 0 To dgvKeywordSearch.Rows.Count - 1
>       Dim chk As DataGridViewCheckBoxCell =
> TryCast(dgvKeywordSearch.Rows(i).Cells(0), DataGridViewCheckBoxCell)
>   chk.Value = False
>        Next
>
>     End If
>  End If
>
> Hope this will help you !!
>
> Regards,
> Mansi Shah
>
> *** Sent via Developersdex http://www.developersdex.com *** 


1
Bhavin
11/17/2009 12:58:39 AM
Reply:

Similar Artilces:

Creating a Formula to Format Column automatically? #5
They're just name values, pulled from a database. What was strange i that some of the formats tok correctly, others applied another condito (i.e. Sally Smith was supposed to be green but came out red)P -- bludovic ----------------------------------------------------------------------- bludovico's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1480 View this thread: http://www.excelforum.com/showthread.php?threadid=26434 ...

Column Width Behavior
I use pivot tables alot - and I am working with a pivot table where I've set the column width to 9. When I pivot new information in, the column width automatically adjusts to fit, then I have to go and reset the columns back to 9. Is there anyway to override this "adust to fit" behavior and just let the pivot table fit as much text as it can into the column width I specify? Kirk, Unselect the 'Autoformat Table' option in the Options section of the Pivot Table. HTH, Gary Brown "Kirk P." wrote: > I use pivot tables alot - and I am working with a pi...

"Changed by" Column is empty
Outlook 2003/Exchange 2000 Hi, in my mailbox, the "Changed by" column remains empty throughout all folders. When I change to my Team Mailbox, the "Changed by" column has the desired information. Even when I move a mail from the Team Mailbox to my mailbox, the "Changed by" column remains empty. Is this a bug or I am doing something wrong. Thank you very much. Christoph ...

Printing wide columns
Hi all I have a spreadsheet that I want to print. It's only 2 columns, but the second column is very wide. I seem only able to print the first column. However if I reduce the width of column B to 88 or less it prints both columns. is this usual? I'm running XP. Thanks Really would depend on how big the paper your printing on to is. Print Preview. Page Setup Then adjust to 1 by 1 or % of actual size to fit onto how ever many pages you want. "Richard" wrote: > Hi all > > I have a spreadsheet that I want to print. It's only 2 > columns, but the seco...

Icon in Attachments Column does not always show up
We've seen some cases where a message with an attachment does not have the paper clip icon in the attachments column in the table view. It's in Outlook 2000 and 2002. ...

Column limit
I am trying to add for custom fields to the CRM Schema manager. It creates the database portion. As I understand it, SQL can have 1024 columns per base table. I just hit 256 and the event viewer is saying it can't add the column that I am specifying. I find it odd that it stopped at the 8 bit mark. I have been using Picklists, Memo fields and boolean fields for the most part. Any insight is greatly appreciated. ~Graham The database allows a maximum of 8000 characters for every record. Within the CRM Contacts table, this maximum is almost reached when you have just finished instal...

Can I name a column and use it in a formula? (Excel 2007)
I've used named cells many times and they make the formulas much easier to read and much less error-prone. Can this be extended to a column of calculations? Suppose I want to calculate the area of a table of rectangles. My data might look like this: A B C 1 Height Width Area 2 2 3 6 3 3 5 15 4 8 6 48 The formula in C2 is "=A2*B2", which is not as easy to read as "=Height*Width". Is there a way to name Column A "Height" and Column B "Width" and then be able to put something li...

Summing across columns while skipping some columns
Does anyone know of an easy way to accomplish this? In the example below, I do not wish to add the values in columns G18 and J18. =SUMIF(F18:L18,"<>#N/A",F18:L18) Thanks in advance for any replies. Joe How about =SUMIF(F18:L18,"<>#N/A")-SUMIF(G18,"<>#N/A")-SUMIF(J18,"<>#N/A") Note the third argument is not needed since you are summing the same range as you are testing. best wishes -- Bernard Liengme Microsoft Excel MVP people.stfx.ca/bliengme email address: remove uppercase characters "JAG" <JA...

Control can't be edited; it's bound to a replication system column 'TableName'.
I have an Access 2007 accdb database. It hast a table in it with field names TableName and FieldName and a bunch of others. This table has had a small number of records added to it (37) over the life of the database. Suddenly, the two fields TableName and FieldName cannot be edited. That is even if the table is open as a table and you try to type a new record. When you do that an error message is briefly displayed in the left hand end of the Access main window's status bar. For example if you try to input anything into the TableName field you will be blocked and you will briefl...

Rename Columns
Hi All, I was wondering how you rename the column headings from A, B, C to my own choosing. Thanks in advance Hi, You cannot I'm afraid. WHat you should do is type your headings into the top row. Regards, Jan Karel Pieterse Excel MVP >-----Original Message----- >Hi All, >I was wondering how you rename the column headings from A, >B, C to my own choosing. > >Thanks in advance >. > Hi You can't - you only can switch to R1C1 style (column numbers are displayed) and back to column labels. When you want this for better lookout only (without any functional...

How do I force all capital in a column of lower case names?
I read the help, but it doesn't tell me where to enter the formula. If you do not have a blank column next to the mentioned column, then insert one. Enter the formula in a cell adjacent to the cell you want to change, and copy down. Then copy this column, go to the original column, select a cel, right click and click on Paste Special, tick values. Delete the helper column. Iow, with you lower case data in Column E, click on Column F, if not empty, and insert a column. F is then an empty column. Say your data starts in E2, then in F2 enter =UPPER(E2). Move cursor to the botto...

Preventing Column Cell Values from Printing
I have a summary worksheet with several columns of information. There is one particular column (E25:F39) where I don't always want to print the values. Is there some simple way to toggle this column's values on and off just before hitting the print command? I was thinking of using an adjacent tick box outside the print area, which when ticked would print the column values, and vice-versa. I'm looking for a formula that would examine the tick box, and if the tick (letter 'a' in Marlett font) is not present (i.e. cell value = ""), then the values in column (E25:...

Row & Column headers
We just had Excel 2000 installed on one of our PC screens at work, and although the row and column headers look OK at first, when you click on a cell the respective column and row header, instead of just turning bold, turns italic, bold and strikethrough (yeah, go figure) as well! Is something corrupted or has this been set up specifically, and if so how can I change it? I have tried the font options but they just say "Normal". Indeed, the font *is* normal until you click on that row/column. Steve Wylie Have a look at the defined styles in your default workbook. My own ...

creating a equation for a column
how do i set up a rule for excel to do the following. i want column b to be c divided by 11. but i want it to calculate for each row. example c2 reads 110 so it will automatically show 11 in b2. in c4 the number is 990 so b4 should read 99. is there anyway i can create a rule or something along those lines or in each line do i need to type in say b2 (=c2/11) and in b4 (=c4/11)? You can copy the formula in the top formula cell down by dragging its bottom right-hand corner (ie the fill handle - looks like a black square when you point the cursor to it) Place in B2: =C2/11 Drag B2 down B...

Total columns Based on another cells value
Good Day, I trying to use VBA to calculate totals in multiple columns when it see uniques values in another Column..in the example below column "A" contains user names while columns "B, C, D" contain the values I want totaled based on the user name in column "A"...An additional thing would be have it place the values with the user name on a new worksheet. Col A Col B Col C Col D John Smith 1.0 1.0 1.0 John Smith 1.25 1.25 2.0 Mary Johnson .75 1.0 2.5 Jack Johnson ...

how do I extract the last three digits from each cell in column?
I am using excel 2007. Each cell in a column contain varied length of data but ends with "Program ###". I would like to extract ### into an adjacent column for all cells in the first column. Thanks! PeggyT =RIGHT(A1,3) and copy down Vaya con Dios, Chuck, CABGx3 "PeggyT" <PeggyT@discussions.microsoft.com> wrote in message news:0893007D-2776-42CD-942F-16A5B31CB54C@microsoft.com... >I am using excel 2007. Each cell in a column contain varied length of data > but ends with "Program ###". I would like to extract ### into an adjacent ...

Add column "accounts" to activities
Hello there, I'm using the Sales-for-Outlook and want to monitor if all colleagues are using the program correctly. One of the things I've got to look at is whether they link a CRM-activity to an account in the Regarding-field. As far as I can see, the only way to do this is by clicking on each activity and look whether the Regarding-field contains (the right) items. It would be much easier if I could add a column, which contains the accounts filled in in the Regarding-field, to the total activity-list. Does anybody know if this is possible and if so, how can I do this? OK, tha...

How to find a value with multi-column, multi-record list
I have a spreadsheet with $costs arranged according to values in both rows and columns. How do I create drop down lists for both the rows and columns and then return the cell value? eg if I have 5 rows (2-6) and 6 columns (B-G) with costs arranged in each cell within this group how do I create drop downs for each selection, 2-6 and B-G, and return the value to a selected cell. In a typical table of this nature there would be descriptive row and column headers. To do a lookup on this table you would then look for the intersection of a specific row header and a specific column ...

How do I copy numbers from a column across to a row?
I have a spreadsheet with numbers by date down a column and I need to copy the numbers to dates spread across a row. How do I bring them over? If you mean you want to copy eg A1:A10 to B1:K1 then use Paste Special and select Transpose. -- Ian -- "cruncher" <cruncher@discussions.microsoft.com> wrote in message news:A5021A99-A70A-4ED5-B41B-F9A03079AA29@microsoft.com... >I have a spreadsheet with numbers by date down a column and I need to copy > the numbers to dates spread across a row. How do I bring them over? copy the data and use Edit=>PasteSpecial and se...

Is there a way to sum a column using criteria from multiple column
I'm not sure how to ask this, I am currently working on a spreadsheet that has an itemized worksheet depicting each budget approval (Sheet2). I have it tied into our complete budget so that it automatically adds and/or subtracts the amounts according to the date... =SUMIF('Sheet2'!$K:$K,"="&(TEXT(D$5,"mmm-yy")),'Sheet2'!$E:$E) ....but I also need it to be specific to the "BUD#" and "LINE#" (see below). SHEET2 A B C D E BUD # LINE # CAF Date Constructed Key Field Dollar Amount AUBUD 01 12/9/05 =TEXT(C1,"mmm-yy"...

Odd overlapping problem with standard column chart
Hi All, While I've never had a problem with this in the past, this isn't the past... currently, I'm working on a large-scale metrics project, and nearly everything has gone smoothly. However, now, every time I try to create a column chart with multiple y-axes, it overlaps the columns. I've tried changing the sources to both Pivot and standard table forms, I've tried changing the overlap and gap values on the data series for both sources, I've even tried changing it and reverting it to see if it was maybe a bug--no results. I've never once had this problem...

balancing columns in WORD
hI, I am having an unexpected problem with word 2007. I have a document that starts in one column, then switches to two colums and finally reverts to one. The two column part stays perfectly balanced as long as there are no footnotes in the text. As soon as I insert a footnote, the footnote text goes to the bottom of the related column (and this seems OK), but the text is not balanced any longer and the following one-column section is pushed to a new page, even though the section break continuous is present at the end of the last column. I have also tried to insert the footnotes before...

getting info from array but not using column / row numbers
i need to get info from table: Dist / Age 12 13 14 15 100 1.4 2.0 3.0 4.0 200 1.3 2.1 3.1 4.2 300 1.5 2.2 3.2 4.4 400 1.6 2.3 3.4 3.4 So, if i needed to get data for a 14 year old where distance is 300, I need to search both row and column labels to get required row and column numbers in order to retrieve data - in this case 3.2 Any ideas? I can put absolute row and column numbers in, e.g. 3,3 but i need to search labels first based upon contents of another cells (in this case 14 and 300). Assistance greatfully rec...

Creating a Formula to Format Column automatically? #4
Does it matter what order the conditions are in? Some of them worked some didn't -- bludovic ----------------------------------------------------------------------- bludovico's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1480 View this thread: http://www.excelforum.com/showthread.php?threadid=26434 If you have 3 conditions, the order does not matter. What matters is the content of the cell. Not case-sensitive, but do you have any extra spaces if text? If looking for numbers, are they real numbers or text that looks like numbers? You used Joe Blow and...

Cannot add columns to child custom entity of parent custom entity
When I create a custom entity I can add columns to the view from the available list of attributes and once saved and published the view is updated with the new columns. However, if I add another custom entity and create a parent child relationship with the first custom entity then I cannot modify the view columns. I can add new columns but upon saving and publishing the actual view does not change although my change still appear in the customization tool. Found child custom entity view was not the default view but the "Associated View" that needed to be modified. "xcu...