Cannot select specific row on Janus GridEX

3.8k views Asked by At

So I'm accessing a DB through a stored procedure and am able to pull the data I wanted into a popup box. The problem now is that no matter what row I click on, the SAME data keeps populating my fields. How the heck can I choose a particular row, and have that specific row's data pulled from the DB? Thanks for any help

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();
    }
}

I replaced the private void gridEXMon_DoubleClick with:

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();
    }

Popup Dialog

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();
        }
    }

I then sent the rowIndex to the popup:

        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

There are 2 answers

0
Adel Khayata On

Better to get the data from the grid to save the extra call to the database in your ReportInfo class.

Here is the code:

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);
    }

Then your ReportInfo class ctor should be:

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;
    }
}
2
rraszewski On

Have you tried with:

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

Janus has also his own forum available here. You can find there a lot of useful information. For browsing I will use IE. Janus forum works good only with IE...

Edited:

How ReportInfo class can know what record have you selected? Especially that you have fallowing code:

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

Probably you should define ctor with row index:

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