本帖最后由 dapsjj 于 2016-11-1 11:27 编辑
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using MySystem.BLL;
- using MySystem.Common;
- namespace MySystem
- {
- public partial class frmDirectProduction2 : Form
- {
-
- #region
- private string connPCDB = null;
- private CommonPara cp = new CommonPara();
- private string status = "";
- #endregion
- public frmDirectProduction2()
- {
- InitializeComponent();
- }
- #region
-
- private void frmDirectProduction2_Load(object sender, EventArgs e)
- {
- try
- {
- connPCDB = cp.GetConString();
- SqlHelper sh = new SqlHelper(connPCDB);
- sh.Param = sh.GetNewParam();
- sh.Param.AddParam("@TYPE", SqlDbType.Int, 0);
- DataSet ds = sh.ExecuteDatasetSP("MyProc", ref sh.Param, 30000);
- setSpreadData(ds.Tables[0]);
- }
- catch (Exception)
- {
- LogUtil.log("出错");
- }
- }
- #endregion
- #region spread
- private void setSpreadData(DataTable spdt)
- {
- if (this.sprdMain.ActiveSheet.RowCount > 0)
- {
- this.sprdMain.ActiveSheet.Rows.Count = 0;
- }
- this.sprdMain.ActiveSheet.Rows.Count = spdt.Rows.Count;
- DataRowCollection rows = spdt.Rows;
- int rowCount = rows.Count;
- int nowRow = 0;
- for (int i = 0; i < rowCount; i++)
- {
- sprdMain.ActiveSheet.Cells[nowRow, 0].Value = rows[i]["A列"].ToString();
- sprdMain.ActiveSheet.Cells[nowRow, 1].Value = rows[i]["B列"].ToString();
- sprdMain.ActiveSheet.Cells[nowRow, 2].Value = rows[i]["C列"].ToString();
- sprdMain.ActiveSheet.Cells[nowRow, 3].Value = rows[i]["D列"].ToString();
- sprdMain.ActiveSheet.Cells[nowRow, 4].Value = rows[i]["E列"].ToString();
- sprdMain.ActiveSheet.Cells[nowRow, 5].Value = rows[i]["F列"].ToString();
- //第F列,下标是5,是spread的checkbox类型
- sprdMain.ActiveSheet.Cells[nowRow, 6].Value = rows[i]["G列"].ToString();
- sprdMain.ActiveSheet.Cells[nowRow, 7].Value = rows[i]["H列"].ToString();
-
- nowRow++;
- }
- }
- #endregion
- #region
- private void btnExit_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- #endregion
- private void btnDecideActualData_Click(object sender, EventArgs e)
- {
- if (MessageBox.Show("执行?", "系统软件", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
- {
- return;
- }
- }
- //想让spread单元格失去焦点时触发该事件,去取出被选中的一列的checkbox的状态,
- //请问要如何修改代码能让spread中的一个checkbox在被选中的时候把这个checkbox的值给变量status,
- //当选中超过1个checkbox时提示“选择不能超过1个checkbox”,没有选择checkbox时,提示"需要选择一个checkbox",要如何改代码呢?
- private void sprdMain_LeaveCell(object sender, FarPoint.Win.Spread.LeaveCellEventArgs e)
- {
-
- for (int i = 0; i < sprdMain.Sheets[0].Rows.Count; i++)
- {
- status = sprdMain.Sheets[0].Cells[i, 5].Value.ToString();//复选框所在的列
- }
-
- }
- }
- }
-
复制代码
|
|