hide datagridview include all checkbox - c#

I only want 1 row to display in a DataGridView, so I want to somehow hide the checkbox that appears in the column header.
This checkbox is intended to select all the checkboxes, which I don't want to allow users to do.
I'm trying to avoid hiding the column headers and disguising some labels as if they were headers.
Note: I already have the code to uncheck all the other checkboxes when a user clicks on a different one.
Update: I left out that I populated the data from a data source. The "Include" column was not attached to the data source, but added from the data source wizard.

After some advanced experimentation (i.e. fooling around), I learned that naming a field/column "Selected" in the data source will not only cause it to be automatically included in the data grid view as a checkbox, but the header will not have a checkbox and behaves as desired.
Finagling my way to success ...

Related

Blazor server side table with paging and multirow select feature using bootstrap?

I have a table which display records in a for each loop.Each row has a checkbox to show selected rows.
I want to keep track of the rows selected in the table so that when i navigate back to the pages where I had selected the rows I can see the checkbox checked.
My question.
1.Can I do this somehow without injecting javascript with bootstrap or some logic in the code behind?
If not what other logic can i use to bind the checkbox? (I was thinking keep a list of indices selected and check onrendering the rows but hope there is a nice way to do this)
2.How can I highlight the selected rows when i check the corresponding row checkbox again without injecting javascript.
On further analyzing my requirement and Data I was able to achieve both the above conditions through a collection of indices selected and if conditions while building the UI to render the checkboxes and the styling the rows

Filter a Kendo UI MVC Grid using checked items in a checkbox column

I have a Kendo UI MVC Grid where I'd like to add a special checkbox column.
This column will not be bound to a model but will be used like a sort of filter.
The idea is that users can check some rows and then click a button (for instance the filter icon in the column header). When clicked, the grid should collapse to the selected rows. The way I see it, it is an extra filter, but not the usual way.
The way my users will work with it would be about as follows:
They select a row and play the attached sound file for that row.
If the row holds an interesting sound file, they may check the checkbox and move to a new row -> 1.
After the selection with checkboxes is made, they will click on the checkbox column filter icon.
The selection will then collapse to the rows that were selected.
After this, the collapsed grid may be exported to excel, pdf or whatever…
A multi select grid is not an option as well as a checkboxed column filter because the selection is not instant, but a process over time.
I cannot find how I would make #4 work. Any suggestions? I don't need a complete solution, ideas are welcome.
The best way is to add boolean 'util' property to your model and bind it to a checkbox column. Once your checkbox column will be bound, your button can execute:
dataSource.filter({ field:"Field", operator: "eq", value: true });
As far I know - there is no build kendo way to manage filtering unbounded columns.

Adding a checkbox to a databound DataGridView

I'm working with DataGridView in C#. I fill it with a table from database using BindingSource. After filling the DataGridView I need to add a row of checkboxes that should be first in the table, to enable data filtering in future.
I mean: for example after clicking "Load" button I get DataGridView filled with 4 columns of data and the first row should consists of checkboxes.
I confused. I use
DataGridViewCheckBoxCell checkCell = new DataGridViewCheckBoxCell();
SourceDGV.Rows.Add(checkCell);
I mean here:
But after clicking load button it says You can't add rows to databounded DataGridView
Sorry if ecxeption translated wrong, I translated it from Ukrainian.
Any help appreciated.
Am afraid, there is no concept of whole rows to be of some type(checkbox in your case) in DataGridView. It is other way around. You can have whole column to be of checkbox type. You'd use DataGridViewCheckBoxColumn for that.
Showing checkboxes in whole row even makes no sense for me: Assume you have data bounded Person object to the DataGridView. So there will be columns like Name, Age, Address. Now, on what basis you show checkbox in the row? How can a Name be converted to a bool(which is what checkbox needs as a value)?
One workaround I can think of would be, handle custom painting, If First row paint checkboxes over there and manually handle their click events. But am pretty sure it's not gonna be easy.

DataGrid problems. Using DataSet.Merge with "Edit Template"

I am trying to debug an issue with a WinForm application.
The application uses a DataGridView bound to a DataSet.
The user can select a row and click "Edit" and an Edit Form appears so the user can edit the row and save his changes.
If the DataGridView is sorted by one or more columns and the user edits a row more than once and changes that rows position in the DataGrid (by changing one of the sorted columns TWICE), the DataGridView gets out of sync and I get Exception errors.
Here is how the code is written:
When the user clicks a row and hits edit (the user may only select one row), that row is passed to the EditFom. The edit Form creates an empty DataSet and loads that Row. When the user is done, the calling form uses DataSet.Merge to merge those changes back into its DataSet.
Here are a couple of scenarios that tell me it is womething to do with the "merge" and sorting:
(Note, I never change the actual "sorting", I am talking about changing the value of one of the sorted by columns in one of the rows.)
If the user edits a row directly in the Grid and changes the value of one of the columns being used to sort, then changes it again, etc. The row moves around the Grid, like it should and when the user clicks save, everything saves fine.
If the user edits a row (directly in the Grid OR via the "template") and doesnt change any of the "sort" columns, just makes an edit (therby setting the "State" of the row to Modified, right...), THEN the user edits the row using the Template (which goes through the seperate DataSet and merges the data back when done), and changes one of the columns being sorted (when done, the grid should resort and the row should "move"), the row doesn't get REPAINTED, it stays in the same position in the grid that it was in before the template edit. (Although, the data saves fine and you can refresh the grid and it sorts properly.) Evidently, the DataGrid isn't being notified that the RowChanged in this scenario (or it is, but it isn't doing anything about it).
If the user edits a row directly in the Grid, change a sort column (the row moves), then edits the row using the template and changes that column again, we get the same results as 2, above. The data saves fine, but when the user leaves the edit template, the grid doesn't resort.
(This is the one that causes the Exception error.)
If the user edits a row using the template and changes a sort column and leaves the template, the datagrid resorts and the row moves properly. Then, if the user edits the SAME row using the Template Edit and changes the sort column AGAIN. When the user leaves the edit template, the datagrid doesn't resort and when the user saves the data and the grid refreshes, we get an error:
System.InvalidOperationException: DataTable internal index is corrupted: '5'.
And sometimes, we get an error complaining the primary key is missing.
Any advice on how to "debug" this? I feel like it has something to do with the "internediate" dataset the edit template uses and the "Merge". It is like the DataGrid datasource is getting out of sync with the DataGrid Rows.
I should have done some Google'ing before posting this. It seems to be a common error and I found a HUGE post about this on the MS site. Unfortunately, I haev tried most of their suggestions, but most likely I will find my answer there. I just wanted to make a note of this, in case anyone is interested:
http://social.msdn.microsoft.com/Forums/en/adodotnetdataproviders/thread/18544cd3-1083-45fe-b9e7-bb34482b68dd

How to hide the empty Column

Using C# & asp.net
if there is no data's in the table, gridview displaying one rows (it was empty)
I want to hide the gridview empty row.
How to do this.
Assuming that you can normally delete that one visible row just check that if a field that would normally have a value is empty and the row count is 1 then delete that row.
if(String.IsNullOrEmpty(mydatagrid.Rows[0][0].ToString()) && mydatagrid.Rows.Count==1) //Check a field that would normally have a value
{
mydatagrid.Rows.RemoveAt(0);
}
Let me know if this helps/works
If you are manually data binding than you can check at that time and hide or disable the control if there is no data. If you are data binding using the design view than you should subscribe to the DataBinding or the PreRender events on the control and check then.
you can check if the datatable doesn't have any rows
use:
mydatagrid.DataSource=null;
mydatagrid.DataBind();
As the other two comments you can either check in code and set MyDataGrid.Visible to true or false to hide the entire table, or you can not bind the datasource, or you can EmptyDataTemplate option to display whatever you want when there is no data for the GridView to display normally.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.emptydatatemplate.aspx
The normal behavior for GridView is to render NOTHING if there are no data rows. (Well, almost nothing; it insists on rendering a <div> wrapper, but that'll be empty.)
If you specify an EmptyDataTemplate, however, a one-celled wrapper table is generated to contain whatever is in your template. Even if your template is empty, you'll get that wrapper table (with its one cell, empty). Sounds like the answer to your question is don't specify an EmptyDataTemplate.

Categories