C# .NET - CHECKBOX column in DATagridiview

Asked By Blair Yumi
01-Dec-10 02:49 AM
Hi, can some on help me with my problem?

How can I add a checkbox column programmatically and making it as a first column.

here is my code, but the checkbox is at the last column.

private void Form1_Load(object sender, EventArgs e)
    {
      string stat = "";
      int ave = 0;
      dataGridView1.ColumnCount = 5;


      DataGridViewCheckBoxColumn chk = new DataGridViewCheckBoxColumn();
      dataGridView1.Columns.Add(chk);
      chk.HeaderText = "Check Data";
      chk.Name = "chk";

      dataGridView1.Columns[1].Name = "Substation/Office";
      dataGridView1.Columns[2].Name = "IP Address";
      dataGridView1.Columns[3].Name = "Status";
      dataGridView1.Columns[4].Name = "Average";

      string[] row = new string[] { "ce", "1", stat};
      dataGridView1.Rows.Add(row);
      row = new string[] { " Da", "1.1", stat };
      dataGridView1.Rows.Add(row);
      row = new string[] { "s", "19", stat };
      dataGridView1.Rows.Add(row);
      row = new string[] { "cat", "1", stat };
      dataGridView1.Rows.Add(row);
      row = new string[] { "te", "6.1", stat };
      dataGridView1.Rows.Add(row);
      row = new string[] { "ffice", ".1", stat };
      dataGridView1.Rows.Add(row);
      row = new string[] { "ca", "51.1", stat };
      dataGridView1.Rows.Add(row);
      row = new string[] { "ban", "1", stat };
      dataGridView1.Rows.Add(row);
      row = new string[] { "Office", "1", stat };
      dataGridView1.Rows.Add(row);
      row = new string[] { "or", "19", stat };
      dataGridView1.Rows.Add(row);
      row = new string[] { "Sur", "19", stat };
      dataGridView1.Rows.Add(row);
      row = new string[] { "C", "3.1", stat };
      dataGridView1.Rows.Add(row);
      row = new string[] { "Norte", "1", stat };
      dataGridView1.Rows.Add(row);
      row = new string[] { "Sto", "10", stat };
      dataGridView1.Rows.Add(row);
      row = new string[] { "mail", "1", stat };
      dataGridView1.Rows.Add(row);
    }



the checkbox column always appear at the last column of the grid view.
ANd this is the scenario:

the first column should be a checkbox column and the latter columns accept string values,i can make the 1st column to appear first but i can't add the other columns,can someone help me with this problem? thanks a lot po...
  Lalit M. replied to Blair Yumi
01-Dec-10 02:52 AM
you will get some guide from this link'
http://csharpdotnetfreak.blogspot.com/2009/08/checkall-checkbox-gridview-aspnet.html

  Rohan Dave replied to Blair Yumi
01-Dec-10 03:05 AM
didn't you get answer from below post that you have posted ?

http://www.eggheadcafe.com/community/aspnet/2/10227035/data-grid-view-with-checkbox-column.aspx


did you try by below ?

dataGridView1.Columns[0].Name = "chk"; // header name
  Blair Yumi replied to Rohan Dave
01-Dec-10 03:10 AM
okay that helped...that added another column that appears on the first grid,

but my problem as that i have errors when i'm trying to insert values for the other textbox columns,
 the values are always placed at the first column (w/c is the checkbox column) and its not supposed to happen..can you help me with that? thanks
  Rohan Dave replied to Blair Yumi
01-Dec-10 04:22 AM
obviously it will gives you the error. The reason is that in your stirng array you are just storing 3 values so it will alwayz add value to 0, 1 and 2 cells. So your first column or column on 0 location is Checkbox type so it will gives error..

so do something like that :

 string[] row = new string[] { "true", "ce", "1", stat};
 dataGridView1.Rows.Add(row);
 row = new string[] { "false" ,"Da", "1.1", stat };
dataGridView1.Rows.Add(row);

try by it ..
  Leo replied to Blair Yumi
27-Jan-11 08:32 AM
You should move the statement dataGridView1.ColumnCount = 5; further down,

first create the checkboxcolumn

    DataGridViewCheckBoxColumn chk = new DataGridViewCheckBoxColumn();
    dataGridView1.Columns.Add(chk);
    chk.HeaderText = "Check Data";
    chk.Name = "chk";

then the remaining columns using

dataGridView1.ColumnCount = 5;
Create New Account
help
time, but when I try to import profiles again (using Full or Incremental import) the status stays on Enumerating. There's nothing written in the log file. I found this error the sharepoint log file: 01 / 17 / 2008 13:59:45.30 w3wp.exe (0x0FA0) 0x0AF4 Office Server Office Server Shared Services 7fxb Medium Updating shared object 'Microsoft.Office.Server.Administration.UserProfileApplication' (Id: 84f4e554-5d34-4c29-9e7e-9d4075971819, Version: 63, HashCode: 55803581, Status: Online, Stack: at Microsoft Office.Server.Administration.SharedObjectStore.PutObject(SharedObject sharedObject) at Microsoft.Office.Server.Administration.SharedObject.Update() at Microsoft.Office.Server.UserProfiles.UserProfileConfigManager.StartImport(Boolean fIncremental, String contentSourceName, Boolean fByPassAdminCheck) at Microsoft.Office.Server.UserProfiles
Outlook Mail, along with the other existing options i need to get one option like "Status" under which two sub-options like "Approve" and "Reject" should be there. Upon selecting the Regards, Muppidi. - - pavanmuppidi Outlook Program Add-Ins Discussions Microsoft.VisualStudio.Tools.Applications.Runtime (1) Microsoft.Office.Core.CommandBarControl (1) Office.MsoControlType.msoControlButton (1) Microsoft.Office.Core.CommandBar (1) Microsoft.Office.Interop.Outlook (1) System.Windows.FormsImports (1) Office.CommandBarButton (1) System.Windows.Forms (1) Outlook version? For Outlook 2003 or earlier you can Reminders, Attachment Options. http: / / www.slovaktech.com / products.htm Private Sub Application_ItemContextMenuDisplay(ByVal CommandBar As Office.CommandBar, ByVal Selection As Selection) Static intCounter As Integer On Error GoTo ErrRoutine ' Increment or You need to make sure that you have project references set to Outlook and to Office, and that the Outlook reference is ahead of any other application that exposes a Selection
TSM_BRANCH_MASTER FUNCTION_ID = "2" ZONE_ID = "1" BRANCH_ID = "1" BRANCH_CODE = "Delhi" BRANCH_DESC = "Delhi Main Gate" BRANCH_CATEGORY = "1" STATUS = "A" CREATED_BY = "1" UPDATED_BY = "1" UPDATED_ON = "2010-09-25T08:49:58.420" IPADDRESS = "127.0 1" / > <TSM_BRANCH_MASTER FUNCTION_ID = "2" ZONE_ID = "3" BRANCH_ID = "2" BRANCH_CODE = "BB2" BRANCH_DESC = "BARA BAZAR" BRANCH_CATEGORY = "1" STATUS = "A" CREATED_BY = "1" UPDATED_BY = "1" UPDATED_ON = "2010-09-25T08:51:36.780" IPADDRESS = "127.0 1" / > <TSM_BRANCH_MASTER FUNCTION_ID = "2" ZONE_ID = "2" BRANCH_ID = "3" BRANCH_CODE = "BB3" BRANCH_DESC = "Anna Nagar" BRANCH_CATEGORY = "1" STATUS = "A" CREATED_BY = "1" UPDATED_BY = "1" UPDATED_ON = "2010-10-08T16:39:07.830" IPADDRESS = "127.0 branch_class = "1" / > <TSM_BRANCH_MASTER FUNCTION_ID = "2" ZONE_ID = "4" BRANCH_ID = "4" BRANCH_CODE = "BB4" BRANCH_DESC = "Andheri" BRANCH_CATEGORY = "1" STATUS = "A" CREATED_BY = "1" UPDATED_BY = "1" UPDATED_ON = "2010-09-25T08:52:27.437" IPADDRESS = "127.0 region_id = "3" branch_class = "1" / > <TSM_BRANCH_MASTER FUNCTION_ID = "1" ZONE_ID = "27" BRANCH_ID = "307" BRANCH_CODE = "5141" BRANCH_DESC = "BHAWANIPATNA" STATUS = "A" region_id = "33" / > <TSM_BRANCH_MASTER FUNCTION_ID = "3" ZONE_ID = "8" BRANCH_ID = "7" BRANCH_CODE = "CA2" BRANCH_DESC = "Chennai Ambattur" BRANCH_CATEGORY = "1" STATUS = "A" CREATED_BY = "1" UPDATED_BY = "1" UPDATED_ON = "2010-09-25T10:22:12.890" IPADDRESS = "127.0 1" / > <TSM_BRANCH_MASTER FUNCTION_ID = "3" ZONE_ID = "8" BRANCH_ID = "8" BRANCH_CODE = "AA3" BRANCH_DESC = "Chennai Annanagar" BRANCH_CATEGORY = "1" STATUS = "A" CREATED_BY = "1" UPDATED_BY = "1" UPDATED_ON = "2010-09-25T10:22:42.623" IPADDRESS = "127.0 branch_class = "1" / > <TSM_BRANCH_MASTER FUNCTION_ID = "3" ZONE_ID = "8" BRANCH_ID = "9" BRANCH_CODE = "PN" BRANCH_DESC = "Pune" BRANCH_CATEGORY = "1" STATUS = "A" CREATED_BY = "1" UPDATED_BY = "1" UPDATED_ON = "2010-09-25T10:22:58.420" IPADDRESS = "127.0
successfully, an outlook vsto addin for 2003. But i am unable to install it on office 2007 for one of the machines as, it is unable to install O2003PIA as it also requires office sp2. Whenever i try to install offce sp2 it says product version not found. Is something i am missing. Outlook Program Add-Ins Discussions Outlook 2003 (1) Outlook 2007 (1) Office (1) Word (1) VSTO (1) XP (1) NewInspectorEventHandler (1) SetTrackForReplyForward (1) A VSTO addin compiled of your samples. Have written it for 2003 but this problem is occurring for 2007 office on XP. Have tested it on other xp machine with 2007 and it is working template): internal class InspectorWrapper : WrapperClass { Outlook.Application outlookApp = new Outlook.Application(); public Outlook.Inspector inspector; Office.CommandBar _CommandBar = null; Office.CommandBarButton _TrackButton; Office.CommandBarComboBox _BAComboBox = null; Office.CommandBarComboBox _DueDateText; Office.CommandBarButton _DueDateBtn; WindowHandle owner; Office.CommandBarButton _TBitsBtn; Office.CommandBarButton _SmsBtn; Office.CommandBarComboBox
right-click. This was developed using Extensibility.IDTExtensibility2 interface in Visual Studio, using the Microsoft Office 10.0 Library. The add-in works fine on Office XP. . .any time I right-click an item, it shows a context menu with an added button. The weird thing happens on Office 2007. . . when I first right click the context menu shows correctly. Then if I right 1) Extensibility.IDTExtensibility2.OnBeginShutdown (1) Outlook.OlSaveAsType.olMSG (1) System.IO.Path.GetTempPath (1) Microsoft.Office.Core.CommandBarControl (1) Here is the complete code: Public Class Connect Implements Extensibility.IDTExtensibility2 Private Private _addInInstance As Object Private WithEvents _outApp As Outlook.Application Private WithEvents _ActiveExplorerBars As Microsoft.Office.Core.CommandBars Private WithEvents _conButton As Microsoft.Office.Core.CommandBarButton Private _IgnoreCommandbarsChanges As Boolean Private _currentUser As String = 3D String.Empty Public Sub End If End If End If End Sub Private Sub AddContextButton(ByVal ContextMenu As Microsoft.Office.Core.CommandBar) Dim Control As Microsoft.Office.Core.CommandBarControl Dim controlTag As String = 3D "SalvaDocumentale" 'User cannot play with the Context Menu