无法在Janus GridEX上选择特定行

本文关键字:选择 GridEX Janus | 更新日期: 2023-09-27 18:30:00

因此,我通过存储过程访问数据库,并能够将我想要的数据拉到弹出框中。现在的问题是,无论我点击哪一行,SAME数据都会不断填充我的字段。我怎么能选择一个特定的行,并从数据库中提取该特定行的数据?感谢的帮助

Form1

public partial class DSC_Mon : Form
{
    DSCU_SvcConsumer.MTCaller Caller;
    DataSet dsZA;
    DataSet dsOut;
    public DSC_Mon()
    {
        InitializeComponent();
        Caller = new DSCU_SvcConsumer.MTCaller();
        dsZA = new DataSet();
        dsOut = new DataSet();
    }
    private void DSC_Mon_Load(object sender, EventArgs e)
    {
        timer1.Enabled = true;
    }
    private void LoadData()
    {
        if (!dsZA.Tables.Contains("Query"))
        {
            DataTable dtZA = dsZA.Tables.Add("Query");
            dtZA.Columns.Add("str");
            dtZA.Rows.Add(string.Format(@"exec MON_GetStatus"));
        }
        //dtZA.Rows.Add(string.Format(@"select * from am_company"));
        dsOut.Clear();
        dsOut.Merge(Caller.CallRequest("ZuluAction", dsZA));
        if (gridEXMon.DataSource == null)
        {
            gridEXMon.DataSource = dsOut;
            gridEXMon.DataMember = "Table";
        }
        //gridEXMon.RetrieveStructure();
    }
    private void timer1_Tick(object sender, EventArgs e)
    {
        timer1.Enabled = false;
        LoadData();
        timer1.Enabled = true;
    }
    private void gridEXMon_DoubleClick(object sender, EventArgs e)
    {
        ReportInfo report = new ReportInfo();
        report.ShowDialog();
    }
}

我用替换了私人空隙网格EXMon_DoubleClick

private void gridEXMon_RowDoubleClick(object sender, Janus.Windows.GridEX.RowActionEventArgs e)
    {
        if (e.Row.RowIndex < 0)
            return;
        int rowIndex = Convert.ToInt32(e.Row.RowIndex);
        ReportInfo report = new ReportInfo(rowIndex);
        report.ShowDialog();
    }

弹出对话框

public partial class ReportInfo : Form
{
    public ReportInfo()
    {
        InitializeComponent();
        DSCU_SvcConsumer.MTCaller caller = new DSCU_SvcConsumer.MTCaller();
        DataSet dsZA = new DataSet();
        DataSet dsOut = new DataSet();
        if (!dsZA.Tables.Contains("Query"))
        {
            DataTable dtZA = dsZA.Tables.Add("Query");
            dtZA.Columns.Add("str");
            dtZA.Rows.Add(string.Format(@"MON_ReportInfo"));
        }
        dsOut.Clear();
        dsOut.Merge(caller.CallRequest("ZuluAction", dsZA));
        DataTable dt = dsOut.Tables["Table"];
        DataRow dr = dt.Rows[0];
        if (dt != null)
        {
            systemNameTextBox.Text = dr["System"].ToString();
            contactName1TextBox.Text = dr["Manager"].ToString();
            functionNameTextBox.Text = dr["Function"].ToString();
            durationMSTextBox.Text = dr["Speed"].ToString();
        }
    }

然后我将rowIndex发送到弹出窗口:

        DataTable dt = dsOut.Tables["Table"];
        DataRow dr = dt.Rows[rowIndex];
        systemNameTextBox.Text = dr["System"].ToString();
        contactName1TextBox.Text = dr["Manager"].ToString();
        functionNameTextBox.Text = dr["Function"].ToString();
        durationMSTextBox.Text = dr["Speed"].ToString();
    }

无法在Janus GridEX上选择特定行

最好从网格中获取数据,以便将额外的调用保存到ReportInfo类中的数据库中。

这是代码:

private void gridEXMon_DoubleClick(object sender, EventArgs e)
    {
        if (e.Row.RowIndex < 0)
            return;
        ReportInfo report = new ReportInfo();
        String System = Convert.ToInt32(e.Row.Cells["System"].Value);
        String Manager = Convert.ToString(e.Row.Cells["Manager"].Value);
        String Function = Convert.ToDecimal(e.Row.Cells["Function"].Value);
        String Speed = Convert.ToInt32(e.Row.Cells["Speed"].Value);
        report.ShowDialog(System, Manager, Function, Speed);
    }

那么您的ReportInfo类ctor应该是:

public partial class ReportInfo : Form
{
    public ReportInfo(String System, String Manager, String Function, String Speed)
    {
        InitializeComponent();
        systemNameTextBox.Text = System;
        contactName1TextBox.Text = Manager;
        functionNameTextBox.Text = Function;
        durationMSTextBox.Text = Speed;
    }
}

您尝试过:吗

gridEXMon.DataSource = dsOut.Tables[0];
// next line is not required if you've already defined proper grid structure 
gridEXMon.RetrieveStructure(); 

Janus在这里也有自己的论坛。你可以在那里找到很多有用的信息。对于浏览,我将使用IE。Janus论坛只适用于IE…

编辑:

ReportInfo类如何知道您选择了什么记录?尤其是你有闲置代码:

DataTable dt = dsOut.Tables["Table"];
DataRow dr = dt.Rows[0]; // always first record is taken!

也许您应该用行索引定义ctor:

public ReportInfo(int rowIndex)
{
    ...
    DataTable dt = dsOut.Tables["Table"];
    DataRow dr = dt.Rows[rowIndex];
    ....
}