无法在Janus GridEX上选择特定行

时间:2014-11-11 19:05:19

标签: c# sql-server stored-procedures janus gridex

所以我通过存储过程访问数据库,并能够将我想要的数据拉入弹出框。现在的问题是,无论我点击哪一行,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();
    }
}

我将private void gridEXMon_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();
    }

2 个答案:

答案 0 :(得分:0)

您是否尝试过:

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

Janus还有他自己的论坛here。你可以在那里找到很多有用的信息。对于浏览,我将使用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];
    ....
}

答案 1 :(得分:0)

最好从网格中获取数据,以便在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;
    }
}