Select a row from datagrid

Aug 15, 2008 at 12:08 PM
Hi,

I' m trying to select a row from a DataGrid using the following code:

            ListView xgridview = mainWindow.Get<Core.UIItems.ListView>("xGridView1");
            ListViewRows row = xgridview.Rows;
            row[5].Select();
            row[5].Cells[0].DoubleClick();

When I run the test it passes,but the row don't appear as selected in the application.

Can you tell me where is my mistake?

Thank you in advance
Aug 15, 2008 at 1:31 PM


     try to use the Table items, no the listview

          


 

 

Aug 15, 2008 at 2:26 PM
I tried using Table items, but it couldn't find the datagrid and respectively any other grid items.
I forgot to mention that the application I'm working on is a WPF one.
Coordinator
Aug 15, 2008 at 7:32 PM
Seems alright.
I would check as to what happens when you manually do these two things
Select Row 5 by clicking on it.
Double clicking on first cell of row 5.

Or you can give me some test app on which I can reproduce this then I can help you.
Aug 18, 2008 at 12:38 PM
Manually performed  clicking Row 5 selects the row and the double click on the cell causes to get it in edit mode.

I tried using the following code:
            row[5].Click();  but still the row is not selected.

In other side  row[1].Cells[0].Click();  manages to select the particular row.

I'm not sure if the problem is in White, maybe there is something with our automation peers.

Thanks for the help.
Coordinator
Aug 19, 2008 at 7:25 PM
If it is easy for you to provide me a sample the I would love to investigate this further. By the white clicks at the center of the row when click is called.
Aug 22, 2008 at 6:15 AM

Hi,
I am having the same trouble using white.
The application I am trying to automate has a datagridview item. I am unable to access the elements within the datagrid since I am unable to find a api within white which can do that.
I tried to do the following
            sendsms.Get<Table>(SearchCriteria.ByText("DataGridView")).Row("1"," Row 0").Click();
            sendsms.Get<Table>(SearchCriteria.ByText("DataGridView")).Row("1"," Row 0").Click();
            sendsms.Get<TextBox>(SearchCriteria.ByText("Editing Control")).Text = "xyz";
            sendsms.Get<TextBox>(SearchCriteria.ByText("Message:")).Text = "Test Message From Harshad";
            sendsms.Close();
Now the Row 0 is a cell within the datagrid and I need to click it twice before the textbox named "Message" is accessible. Later i need to set the value into the textbox. So the visibility of textbox depends on the user clicking twice on Row 0.

Please let me know what i need to change in the above code.

-Harshad
Aug 22, 2008 at 7:10 AM
Following is the source code:

namespace WindowsApplication9
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.dataGridView1 = new System.Windows.Forms.DataGridView();
            this.Class = new System.Windows.Forms.DataGridViewComboBoxColumn();
            this.Name = new System.Windows.Forms.DataGridViewTextBoxColumn();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
            this.SuspendLayout();
            //
            // dataGridView1
            //
            this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.Class,
            this.Name});
            this.dataGridView1.Location = new System.Drawing.Point(12, 30);
            this.dataGridView1.Name = "dataGridView1";
            this.dataGridView1.Size = new System.Drawing.Size(240, 150);
            this.dataGridView1.TabIndex = 0;
            //
            // Class
            //
            this.Class.HeaderText = "Class";
            this.Class.Items.AddRange(new object[] {
            "FE",
            "SE",
            "TE",
            "BE"});
            this.Class.Name = "Class";
            //
            // Name
            //
            this.Name.HeaderText = "Name";
            this.Name.Name = "Name";
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 273);
            this.Controls.Add(this.dataGridView1);
           
            this.Text = "Form1";
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.DataGridView dataGridView1;
        private System.Windows.Forms.DataGridViewComboBoxColumn Class;
        private System.Windows.Forms.DataGridViewTextBoxColumn Name;

    }
}


Aug 22, 2008 at 7:51 AM
Let me simplify the question:
How do we access DataGridViewTextBoxColumn and DataGridViewComboBoxColumn() elements within a Datagrid?
-Harshad
Coordinator
Aug 24, 2008 at 4:04 PM
I am not sure whether I understand the question correctly.
If you asking how to get a List of columns in Table then you need to use table.Header.Columns.

If you are asking how to get individual items in a combobox then, it is not implemented in white yet. It is possible to do this because UI Automation shows it. You would have to wait for 0.18.
Aug 28, 2008 at 5:56 AM
Hi Vivek,
The problem is:
I have a datagrid within which there are two columns, DataGridViewTextBoxColumn and DataGridViewComboBoxColumn(). I need to click on the  DataGridViewTextBoxColumn. How can i  access it. Following is the source::

            this.dataGridView1 = new System.Windows.Forms.DataGridView();
            this.Class = new System.Windows.Forms.DataGridViewComboBoxColumn();
            this.Name = new System.Windows.Forms.DataGridViewTextBoxColumn();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
            this.SuspendLayout();
            //
            // dataGridView1
            //
            this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.Class,
            this.Name});
            this.dataGridView1.Location = new System.Drawing.Point(12, 30);
            this.dataGridView1.Name = "dataGridView1";
            this.dataGridView1.Size = new System.Drawing.Size(240, 150);
            this.dataGridView1.TabIndex = 0;
            //
            // Class
            //
            this.Class.HeaderText = "Class";
            this.Class.Items.AddRange(new object[] {
            "FE",
            "SE",
            "TE",
            "BE"});
            this.Class.Name = "Class";
            //
            // Name
            //
            this.Name.HeaderText = "Name";
            this.Name.Name = "Name";
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 273);
            this.Controls.Add(this.dataGridView1);
           
            this.Text = "Form1";
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
            this.ResumeLayout(false);


I tried various methods to access. Please let me know if i am missing something.

-harshad
Coordinator
Aug 29, 2008 at 3:07 PM
I dont know whether you tried this:
table.Header.Columns[0].Click()
Dec 4, 2008 at 10:33 AM
I've found out the reason for this bug, in my scenario the row is not selected when the headers are wide enough to make the horizontal scrollbar of a listview appear.
In that scenario the select will make the listview to scroll searching the row but will fail to perform the select, if I manually fix the column's width to avoid the horizontal scroll then the select will be performed correctly.

Regards
Dec 4, 2008 at 12:18 PM
Just forgot to mention that the horizontal scrollbar is covering the selected row. If I maximize the window, the listview gets bigger and due to that, the scrollbar is automatically removed, then it works.
Coordinator
Dec 5, 2008 at 3:11 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Dec 5, 2008 at 3:16 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Jun 24, 2009 at 12:09 PM

I have stumbled over exactly the same problem, using a third party datagrid.
The problem only occurs when the visible part of the grid is less than half the horizontal length required to display the full grid.

This seems to happen because the selection operation attempts to select a row by selecting the mid-point of the complete row-area, rather than the mid-point of the visible part of the row-area.

I have a hack which gets around this problem. It uses scrolling to display the horizontal centre of the datagrid so that the mid-point of the row is visible:

recordDataGrid.ScrollBars.Horizontal.SetToMinimum();
var min = recordDataGrid.ScrollBars.Horizontal.Value;
recordDataGrid.ScrollBars.Horizontal.SetToMaximum();
var max = recordDataGrid.ScrollBars.Horizontal.MaximumValue;
recordDataGrid.ScrollBars.Horizontal.SetToMinimum();

var midValue = (max - min) / 2.0;
while (recordDataGrid.ScrollBars.Horizontal.Value < midValue)
{
  recordDataGrid.ScrollBars.Horizontal.ScrollRight();
}