tag:blogger.com,1999:blog-6837250508009744375.post6302020754815978227..comments2023-05-17T19:46:47.920+05:00Comments on Arsalan Tamiz: Using DataGridView CheckBox Column as RadioButton (OptionButton)Arsalan Tamizhttp://www.blogger.com/profile/03883319971948565803noreply@blogger.comBlogger19125tag:blogger.com,1999:blog-6837250508009744375.post-59030875369613867362013-11-26T14:09:28.080+05:002013-11-26T14:09:28.080+05:00Good point about the ad-hoc Cell value viewing / c...Good point about the ad-hoc Cell value viewing / copying (for *multi*-column grids). I actually don't use FullRowSelect (in my multi-column grids) for that reason. Having a RadioButton Column would allow the current selected *row* to be indicated while the user selects various cells on various rows for viewing / copying. Although, that brings up another point. For a *single* column grid that's just simulating a RadioButton group in grid format (by artificially adding a RadioButton column), I would think ease-of-selection far outweighs the unlikely viewing / copying needs so that you'd probably want to make clicking on *any* column (not just the RadioButton column) select the whole the row in which case you might as well just use MultiSelect = False and FullRowSelect. It seems your example would highlight the benefits / applicability more if it were of a *multi*-column grid that uses a RadioButton column that allows the the current / newly selected row to continue to be indicated while the user selects various cells for viewing / copying.Anonymoushttps://www.blogger.com/profile/04015183628100524834noreply@blogger.comtag:blogger.com,1999:blog-6837250508009744375.post-65526278227106146102013-11-26T13:11:22.966+05:002013-11-26T13:11:22.966+05:00@Tom Chien:
100% agreed what you said.
But look ...@Tom Chien:<br /><br />100% agreed what you said.<br /><br />But look it like that, since the DataGridView control representing the Data in a Tabular Format, so user has a chance to scroll through columns and rows to check. And sometimes they also click on one or more cells and try to copy some value from there. This approach gives a relaxation that you have selected some particular line, now you can freely move here or there select and copy the values you want or explore the data.<br /><br />Otherwise MultiSelect=False and FullRowSelect should provide the same behaviour.Arsalan Tamizhttps://www.blogger.com/profile/03883319971948565803noreply@blogger.comtag:blogger.com,1999:blog-6837250508009744375.post-75625520474173575412013-11-26T04:58:36.312+05:002013-11-26T04:58:36.312+05:00If the user didn't care about the cosmetic vis...If the user didn't care about the cosmetic visual of a Radio Button Column and having just the Button vs. the whole Row highlighted, how is the CellContentClick doing anything functionally different from just setting MultiSelect = False and SelectionMode = FullRowSelect?<br />If not, have users had a significant problem with just clicking anywhere on a Row to select one and only one item (i.e. like they do in ComboBox'es and List's)?Anonymoushttps://www.blogger.com/profile/04015183628100524834noreply@blogger.comtag:blogger.com,1999:blog-6837250508009744375.post-88368891316266898012012-12-13T21:26:29.811+05:002012-12-13T21:26:29.811+05:00Excellent post. This saved me a few hours.Excellent post. This saved me a few hours.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6837250508009744375.post-90296319294586344372012-11-03T08:18:49.325+05:002012-11-03T08:18:49.325+05:00Very helpful. I struggled for a couple of hours to...Very helpful. I struggled for a couple of hours to convert this into Powershell. If anyone is interested this is the PS translation.<br />NB: In my project only the read only columns where radio boxes<br /><br />$datagridview1_CellContentClick=[System.Windows.Forms.DataGridViewCellEventHandler]{<br /> $column = $datagridview1.Columns[$_.ColumnIndex]<br /> if($column.ReadOnly -eq $true){<br /> $dataRowView = $datagridview1.Rows[$_.RowIndex].DataBoundItem<br /> if($dataRowView -ne $null){<br /> $table = $serverDS.Tables["Server"]<br /> foreach ($row in $table.Rows){<br /> $row.Item($column.Index) = $false<br /> }<br /> $dataRowView.Item($_.ColumnIndex) = $true<br /> }<br /> }<br /> }<br /> <br /> $datagridview1_CellPainting=[System.Windows.Forms.DataGridViewCellPaintingEventHandler]{<br /> $column = $datagridview1.Columns[$_.ColumnIndex]<br /> if($column.ReadOnly -eq $true -and $_.RowIndex -ge 0){<br /> $_.PaintBackground($_.ClipBounds, $true)<br /> [System.Drawing.Rectangle]$rectRadioButton = New-Object 'System.Drawing.Rectangle'<br /> $rectRadioButton.Width = 14<br /> $rectRadioButton.Height = 14<br /> $rectRadioButton.X = $_.CellBounds.X + ($_.CellBounds.Width - $rectRadioButton.Width) / 2;<br /> $rectRadioButton.Y = $_.CellBounds.Y + ($_.CellBounds.Height - $rectRadioButton.Height) / 2;<br /> if($_.Value -eq $false){<br /> [System.Windows.Forms.ControlPaint]::DrawRadioButton($_.Graphics,$rectRadioButton,[System.Windows.Forms.ButtonState]::Normal)<br /> }else{<br /> [System.Windows.Forms.ControlPaint]::DrawRadioButton($_.Graphics,$rectRadioButton,[System.Windows.Forms.ButtonState]::Checked)<br /> }<br /> $_.Paint($_.ClipBounds, [System.Windows.Forms.DataGridViewPaintParts]::Focus)<br /> $_.Handled = $true<br /> }<br /> }<br /><br />$datagridview1.add_CellContentClick($datagridview1_CellContentClick)<br /> $datagridview1.add_CellPainting($datagridview1_CellPainting)Anonymoushttps://www.blogger.com/profile/06051376696541942721noreply@blogger.comtag:blogger.com,1999:blog-6837250508009744375.post-38948386374009752722012-02-07T15:58:19.482+05:002012-02-07T15:58:19.482+05:00@Sahil:
I've actually created a Typed DataSet...@Sahil:<br /><br />I've actually created a Typed DataSet here. You need to do use your own DataSet/DataTable or whatever datasource you have used with DataGridView control.<br /><br />Download the Source and check it, you may understand what is going on.Arsalan Tamizhttps://www.blogger.com/profile/03883319971948565803noreply@blogger.comtag:blogger.com,1999:blog-6837250508009744375.post-32578133889021281792012-02-07T02:13:06.140+05:002012-02-07T02:13:06.140+05:00what is Dim rowShutDownOption As ShutdownOptionDat...what is Dim rowShutDownOption As ShutdownOptionDataSet.ShutDownOptionsRow in this. it gives me error and i dont know wt to replace with this? can some1 help me in it plz? <br />my data grid name is datagridview1 and chech box column is column1 . plz helpsahilhttps://www.blogger.com/profile/07547608798328054927noreply@blogger.comtag:blogger.com,1999:blog-6837250508009744375.post-59721673997247869602010-02-12T11:07:27.939+05:002010-02-12T11:07:27.939+05:00@Seminyak Villas
Sorry I didn't get you. We a...@Seminyak Villas<br /><br />Sorry I didn't get you. We already have a check box column built-in for DataGridView control you just have to add it in Design Mode or through coding.Arsalan Tamizhttps://www.blogger.com/profile/03883319971948565803noreply@blogger.comtag:blogger.com,1999:blog-6837250508009744375.post-35206947491814662562010-02-10T08:55:41.102+05:002010-02-10T08:55:41.102+05:00Thx...
Good article.
How can we make a datagridvi...Thx...<br /><br />Good article.<br />How can we make a datagridview with checkbox type colum with simple coding.Seminyak Villashttp://baliseminyakvillasrental.comnoreply@blogger.comtag:blogger.com,1999:blog-6837250508009744375.post-85274225926973830132009-11-10T18:04:29.334+05:002009-11-10T18:04:29.334+05:00Thank you! I was looking for it quite long, but t...Thank you! I was looking for it quite long, but this looks so nice and easy!Barmanhttps://www.blogger.com/profile/09342199772759532465noreply@blogger.comtag:blogger.com,1999:blog-6837250508009744375.post-47266568356461549662009-09-11T00:54:19.110+06:002009-09-11T00:54:19.110+06:00Thanks flacoman for the input.Thanks flacoman for the input.Arsalan Tamizhttps://www.blogger.com/profile/03883319971948565803noreply@blogger.comtag:blogger.com,1999:blog-6837250508009744375.post-54381285536157964562009-09-09T00:54:49.803+06:002009-09-09T00:54:49.803+06:00Great post!!!
Tip:
If you want Windows XP styles...Great post!!!<br /><br />Tip:<br /><br />If you want Windows XP styles in the radio buttons you can use this code in the cellpaint event:<br /><br /> If e.ColumnIndex = 1 AndAlso e.RowIndex >= 0 Then<br /> e.PaintBackground(e.ClipBounds, True)<br /><br /> Dim p As Point<br /> p.X = e.CellBounds.X + (e.CellBounds.Width - 14) / 2<br /> p.Y = e.CellBounds.Y + (e.CellBounds.Height - 14) / 2<br /><br /><br /> If IsDBNull(e.Value) OrElse e.Value = False Then<br /> RadioButtonRenderer.DrawRadioButton(e.Graphics, p, VisualStyles.RadioButtonState.UncheckedNormal)<br /> Else<br /> RadioButtonRenderer.DrawRadioButton(e.Graphics, p, VisualStyles.RadioButtonState.CheckedNormal)<br /> End If<br /><br /> e.Paint(e.ClipBounds, DataGridViewPaintParts.Focus)<br /><br /> e.Handled = True<br /> End If<br /><br />GreetsFlacomanhttps://www.blogger.com/profile/15715097100099715530noreply@blogger.comtag:blogger.com,1999:blog-6837250508009744375.post-63996977056945027762009-07-29T18:42:03.516+06:002009-07-29T18:42:03.516+06:00@TD,
Atleast "option button" column sho...@TD,<br /><br />Atleast "option button" column should be readonly.Arsalan Tamizhttps://www.blogger.com/profile/03883319971948565803noreply@blogger.comtag:blogger.com,1999:blog-6837250508009744375.post-83970267338141292492009-07-28T22:56:19.582+06:002009-07-28T22:56:19.582+06:00Arsalan, Thanks again for the post. This works pre...Arsalan, Thanks again for the post. This works pretty well, but I actually do need the user to have the ability to add and update rows. Can you elaborate on the additional problems and complexities that you mention? When the grid is not Read-Only the procedure’s behavior is really flaky. <br /><br />TDTDhttps://www.blogger.com/profile/13604218371895176858noreply@blogger.comtag:blogger.com,1999:blog-6837250508009744375.post-57848357069581203172009-07-28T07:08:59.484+06:002009-07-28T07:08:59.484+06:00Thanks! This was exactly what I needed.Thanks! This was exactly what I needed.TDhttps://www.blogger.com/profile/13604218371895176858noreply@blogger.comtag:blogger.com,1999:blog-6837250508009744375.post-12824298162914530762009-03-26T21:15:00.000+05:002009-03-26T21:15:00.000+05:00Hi Ole,The thing which you required is alot simple...Hi Ole,<BR/><BR/>The thing which you required is alot simpler. Do the followings<BR/><BR/>1) Create a DataTable with 4 Fields. 3 Boolean and 1 for File Name<BR/>2) Bind this DataTable with DataGridView<BR/>3) Make the first 3 Columns Read-only<BR/>4) In the CellContentClick Event Handler, use this logic:<BR/>if Clicked Column = any of first 3 column Then<BR/> Get the DataTable Row<BR/> Make all the other boolean columns = False<BR/> And then Set the clicked column = True<BR/>End IfArsalan Tamizhttps://www.blogger.com/profile/03883319971948565803noreply@blogger.comtag:blogger.com,1999:blog-6837250508009744375.post-38949867489687898242009-03-25T18:03:00.000+05:002009-03-25T18:03:00.000+05:00Hi,Thanks for this code. It helped me a lot.Unfort...Hi,<BR/>Thanks for this code. It helped me a lot.<BR/><BR/>Unfortunatly i am not good enough in VB, because i have some trouble with my project.<BR/>I want to have a datagrid with three columns of RadioButtons an one Column with a List of filenames.. If i click on one RadioButton, i want the other RadioButtons in this particular row to be deselected...<BR/><BR/>Can anybody provide some help???<BR/><BR/>Thanks<BR/>OleAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-6837250508009744375.post-88810648621092403162009-01-16T13:21:00.000+05:002009-01-16T13:21:00.000+05:00Hi,Thank you very much. This code has helped me a ...Hi,<BR/>Thank you very much. This code has helped me a lot and Saved lot of time. Thank you very much.Unknownhttps://www.blogger.com/profile/14186677586683285895noreply@blogger.comtag:blogger.com,1999:blog-6837250508009744375.post-57451929093406511942008-10-13T21:46:00.000+06:002008-10-13T21:46:00.000+06:00great post thanks, here is the C# translation of t...great post thanks, here is the C# translation of the Painting events. Note, the column I needed this for was titled "Primary":<BR/><BR/>private void gvDocumentList_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)<BR/> {<BR/> if (e.ColumnIndex == gvDocumentList.Columns["Primary"].Index && e.RowIndex >= 0)<BR/> {<BR/> e.PaintBackground(e.ClipBounds, true);<BR/><BR/> Rectangle rectRadioButton = new Rectangle();<BR/><BR/> rectRadioButton.Width = 14;<BR/> rectRadioButton.Height = 14;<BR/> rectRadioButton.X = e.CellBounds.X + (e.CellBounds.Width - rectRadioButton.Width) / 2;<BR/> rectRadioButton.Y = e.CellBounds.Y + (e.CellBounds.Height - rectRadioButton.Height) / 2;<BR/><BR/> if (e.Value == DBNull.Value || (bool)e.Value == false)<BR/> {<BR/> ControlPaint.DrawRadioButton(e.Graphics, rectRadioButton, ButtonState.Normal);<BR/> }<BR/> else<BR/> {<BR/> ControlPaint.DrawRadioButton(e.Graphics, rectRadioButton, ButtonState.Checked);<BR/> }<BR/><BR/> e.Paint(e.ClipBounds, DataGridViewPaintParts.Focus);<BR/><BR/> e.Handled = true;<BR/> }<BR/> }Mr. Cheezlehttps://www.blogger.com/profile/16019208229230039023noreply@blogger.com