Click here to Skip to main content
15,900,461 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to checked true all datagrid view checkbox column on button click.
Posted

1 solution

I solved my self.

C#
public void SelectAllDataGridViewCheckBoxColumn(CheckBox chk, DataGridView dgv, string DatagridViewColumnName)
       {
           if (chk.Checked == true)
           {
               if (dgv.Rows.Count > 0)
               {
                   foreach (DataGridViewRow row in dgv.Rows)
                   {
                       (row.Cells[DatagridViewColumnName] as DataGridViewCheckBoxCell).Value = true;
                   }
               }
           }
           else if (chk.Checked == false)
           {
               if (dgv.Rows.Count > 0)
               {
                   foreach (DataGridViewRow row in dgv.Rows)
                   {
                       (row.Cells[DatagridViewColumnName] as DataGridViewCheckBoxCell).Value = false;
                   }
               }
           }
       }
 
Share this answer
 
v2
Comments
Shambhoo kumar 5-Jul-13 7:58am    
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;

namespace FileUploadOrDownload
{
public static class UploadDownload : Form
{
public UploadDownload()
{
InitializeComponent();
}

#region Variable Declaration

public string query, constr;
public SqlCommand com;
public SqlConnection con;

string filePath;
string filename1;
string ext ;
string type ;

#endregion

public void connection()
{

constr = ConfigurationManager.ConnectionStrings["FileUploadDownload"].ToString();
con = new SqlConnection(constr);
con.Open();

}

private void btnBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog ObjOpenFileDialog = new OpenFileDialog();
ObjOpenFileDialog.Filter = "Document Files(*.doc; *.docx; *.pdf)|**.doc; *.docx; *.pdf";
if (ObjOpenFileDialog.ShowDialog() == DialogResult.OK)
{
txtFilePath.Text = ObjOpenFileDialog.FileName;
}
filePath = txtFilePath.Text;
filename1 = Path.GetFileName(filePath);
ext = Path.GetExtension(filename1);
type = String.Empty;


}

private void btnUpload_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtFilePath.Text) || string.IsNullOrWhiteSpace(txtFilePath.Text))
{
MessageBox.Show("Please Select File", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
try
{
switch (ext)
{
case ".doc":

type = "application/word";

break;

case ".docx":

type = "application/word";

break;

case ".pdf":

type = "application/PDF";

break;
}

if (type != String.Empty)
{
connection();
StreamReader SR = new StreamReader(filePath);
byte[] bytes = SR.CurrentEncoding.GetBytes(SR.ReadToEnd());
query = "insert into Wordfiles(Name,type,data)" + " values (@Name, @type, @Data)";
com = new SqlCommand(query, con);
com.Parameters.Add("@Name", SqlDbType.VarChar).Value = filename1;
com.Parameters.Add("@type", SqlDbType.VarChar).Value = type;
com.Parameters.Add("@Data", SqlDbType.Binary).Value = bytes;
com.ExecuteNonQuery();
MessageBox.Show("Word File Uploaded successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
BindData();
}
else
{
MessageBox.Show("Please Select File", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
{

}

}
}

private void Form1_Load(object sender, EventArgs e)
{
BindData();
}

private void BindData()
{
connection();
query = "Select * from Wordfiles";
SqlDataAdapter da = new SqlDataAdapter(query, con);
DataSet ds = new DataSet();
da.Fill(ds);
colID.DataProperty

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900