.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

wpf datagridview checkbox column selection not working fine.

Posted By:      Posted Date: August 27, 2010    Points: 0   Category :WPF
Hi Experts,in my c#.net windows based wpf application i added  a datagridview.dynamically i added checkboxcolumn to that datagridview DataGridViewCheckBoxColumn cbCol = new DataGridViewCheckBoxColumn(); GridSource.Columns.Add(cbCol); and another column is string. to this column am hardcoding the values DataTable _datatable = new DataTable(); _datatable.Columns.Add("Name", typeof(string)); _datatable.Rows.Add("CSRs"); _datatable.Rows.Add("Customers"); GridSource.DataSource = _datatable; till here fine am getting two columns (checkbox and Name)when i am trying to check those checkboxes problem comming.am trying to get the count of the checked rows for that i used below code int cbcount = 0; foreach (DataGridViewRow _dgRow in GridSource.Rows) { if ((bool)_dgRow.Cells[0].Value) cbcount++; } cbcount will give the checked count.but the problem raising here if i check 2 rows it giving 1if i check 5 rows it giving 4if i check 1 row it giving me 0means am getting n-1 resultwhere i did wrong??

View Complete Post

More Related Resource Links

WPF Datagrid with multiple row selection/checkbox column template

Hello, I am using the WPF Toolkit Datagrid with a checkbox defined in a template column/template cell. We are using the checkbox template so that selecting the checkbox will also highlight the row in the datagrid. Here is the template definition: <dg:DataGridTemplateColumn MinWidth="50" Width="Auto" Header="" CanUserReorder="False"> <dg:DataGridTemplateColumn.CellTemplate> <DataTemplate> <CheckBox IsChecked="{Binding Path=IsCheckedm, Mode=TwoWay}" /> </DataTemplate> </dg:DataGridTemplateColumn.CellTemplate> </dg:DataGridTemplateColumn> We are allowing multiple row selection in the datagrid and using MVVM (using MVVM Light). We would like to keep a list in the View Model of selected rows as they are selected/unselected. Any suggestions on how we can leverage MVVM to keep the list of selected/unselected elements current. Many Thanks --Sam

How to Change the Color of Link Label which is a Datagridview Column on a Row Selection?

Hi All I have a Link label as one of the column of Datagridview & also my SelectionBackColor set to Blue. Is there any way that i can change the link label color on a particular row selection as now my selectionbackcolor & link label color is matching...I am unable to the contents of that link label column. Should i do this on design level or in code level? Pls Help

Checkbox will show panel based on selection without postback.. how to do



I have Two Checkbox in my asp.net textbox..

First what i want is

based on two checkbox user has to be select any one only..

if checkbox1 is selected then Panel1 visible true without postback

if checkbox2 is selected then Panel2 visible true without postback

In sharepoint excel working fine in office 2007 but not in office 2010


Hi All,

we receive error  while trying to create excel sheet using the template we have uploaded on the SharePoint 2007.


This occurs on a machine that has Office 2010 installed. Earlier the machine had Office 2007 and everything was working fine.


Can you let me know why is problem is coming and how to resolve this.



Sanjeev Tiwari


Hi this method is working fine need filter how


private void GetData()
        for (int i = 0; i < Gridview1.Rows.Count; i++)
            DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
            DataRowView drv = dv[i];

validate the selection of atleast one checkbox in the gridview using javascript


 i have a gridview with a checkbox in the templatefield as given  below,

<asp:GridView runat="server" ID="gvAsgnHw"  AutoGenerateColumns="False"   >
        <asp:CheckBox id="cbAsgnHwGrid"   runat="server" /> </ItemTemplate></asp:TemplateField>

         <asp:BoundField DataField="Resource_id" HeaderText="Resource ID"/>
        <asp:BoundField DataField="Resource_name" HeaderText="Hardware Name" />

I want to check the selection of atleast one checkbox on a button click using javascript.
pls help

Working with In-Memory Open XML Documents (Office Talk Column)

Working with Open XML Documents without loading from a file or saving to a file is important when you build applications that work with Microsoft SharePoint Server 2010 or Microsoft ASP.NET Web applications.

Web Part working fine on the top-level page but 'Not Safe' error on lower-level pages.


I have created a Web Part which reads and parses the SharePoint logs in order to display usage information of the page it resides on.  The Web Part works perfectly on the top page, reading and displaying the information desired.  However, once the Web Part is added to any page lower in the site heirarchy (sub-page) the same Web Part throws the following error:

Web Part Error: A Web Part or Web Form Control on this Page cannot be displayed or imported. The type could not be found or it is not registered as safe.

Show Error Details
Hide Error Details

[UnsafeControlException: A Web Part or Web Form Control on this Page cannot be displayed or imported. The type could not be found or it is not registered as safe.]
  at Microsoft.SharePoint.ApplicationRuntime.SafeControls.GetTypeFromGuid(Guid guid)
  at Microsoft.SharePoint.WebPartPages.SPWebPartManager.CreateWebPartsFromRowSetData(Boolean onlyInitializeClosedWebParts)

Of course the current version of the Web Part is in the SafeControls list on the web.config.

The Web Part was originally designed to return site activity only for the top default.aspx page and worked fine but started to fail in the manner described above once I added the following line of code to return a SPCo

datagridview row selection and coloring.

HI !I am a novice in C#.net. I have a datagridview on my form. I want to change the row color by rolling over the mouse on the row not by clicking on the row and when mouse mouse leave the row then the row color is back to the original color. I want to know that which event should i use?any help would be appriciated.

DataGridView>Edit Columns> Column Read Only property is unwilling to change

Hello, I am facing the following mystery: When changing the read only property of a column to false and reopening the "edit columns" window, it mysteriously turns back to true. Even when closing the designer and changing it in the designer code, the resulting execution does not allow edit, as well as when re-opening the designer you see true again.             this.numberDataGridViewTextBoxColumn1.DataPropertyName = "Number";             this.numberDataGridViewTextBoxColumn1.HeaderText = "Number";             this.numberDataGridViewTextBoxColumn1.Name = "numberDataGridViewTextBoxColumn1";             this.numberDataGridViewTextBoxColumn1.ReadOnly = true;//False is required We thought it might be related to data binding. rebinding the grid did not help as well. The is no other place in the code where it changes. Please advice, Thanks

Most efficient way to check whether a DataGridView contains some specific text at a specific column

Dear All,   I am looking at the most efficient way to check whether a specific column of a DataGridView contains some text. For example I have a list of firs names and I would like to check whether the text "Bob" already exists in that columns. I would like to avoid to loop through each row but what thinking of using something with "Contains".   Anybody has an idea ?   Cheers,   Kalos

Missing DataContext! Was working fine, now it's hosed

So I have a web application, set up for .NET 4.0 ... I had a robust LINQ TO SQL Classes object, and it was running just fine. But I needed to make a schema change so I altered my database. No problem. Then I went into my .dbml file and deleted the table I had been working on. Then I re-added the table by dragging it from the server explorer. However, now my code is throwing a number of errors, all saying they can't find my DataContext, called ModelDataContext. I hadn't changed any other app code, so I am really confused!Error 3 The type or namespace name 'ModelDataContext' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Ed\Projects\NBAdminPanel\NBAdminPanel\WebApplication1\DynamicData\CustomPages\Accounts\Edit.aspx.cs 49 29 NBAdminPanel The type or namespace name 'ModelDataContext' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Ed\Projects\NBAdminPanel\NBAdminPanel\WebApplication1\DynamicData\CustomPages\Accounts\Edit.aspx.cs 49 29 NBAdminPanelSo basically my app no longer knows about the class generated from this DBML file. I have tried recreating it by deleting the old one and readding objects to the new one, no dice. I am at my wits end; hoping I don't have to junk the project and start a new one! My DBML file is still in MyProject.App_Code. 

Reconhecer checkBox dentro de DataGridView em Windows Form com um evento checkedChange...

Então ... eu to com um grid e dentro tenho o checkBox... quando a pessoa selecionar ele vai deixar a linha amarela... quando tirar a seleção ele muda a linha... e caso fique selecionado ao apertar um botao de insert... o sistema vai cadastrar o que esta selecionado... mas nao consigo pegar os valores dentro do grid...

How to make a DataGridView Cell/Column not enterable / selecatble

Hi, I am trying to make a Column in a DataGridView non-entaerable (the user should not be able to set focus to the cell neither using the mouse nor the keyboard). I already tried to change the CurrentCell property in the CellStateChanged. But in this event-handler the CurrenCell is the "old" one; setting it to any value doesn't help, because the value is set after calling this procedure. In Delphi there is an event-handler for entering a cell, where you can tell whether the user is allowed to enter a cell. Is there anything comparable in C#? Any other suggestions?

datagridview add data a column at a time

How do I add to a datagridview a column at a time? I see at http://msdn.microsoft.com/en-us/library/5s3ce6k8.aspx that it is possible to do it a row at a time. I was looking for something similar.      

Inserting Records Based on Checkbox Selection in a Gridview

Using checkboxes, can the row of record(s) be inserted into a database? I am populating a Gridview. Done. A checkbox field has been added, when the user selects one or more rows, a submit button (which is not working) needs to inserting those records into a table. The insert statment will work outside of the page but is not working using the scenario I jut described. Is this task as I have outlined doable? txs Ayomide

Unable to Bind a CheckBox to an Oracle column

The code below works great in SQL Server with a BIT column.  How do you get it to work in Oracle?  I've tried number(1), char(1)...etc but nothing works!  Using Eval is no good becuse that breaks the Update. <asp:CheckBox ID="cbxStatus" runat="server" Checked='<%# Bind("status") %>' /> Always get this error: System.InvalidCastException: "Specified cast is not valid".  Anyone know the trick to making this work with Bind? 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend