0

I am using a DataGridView to store some search results but can't seem to get the scroll bar on the grid to work.

I have attribute ScrollBars set to Vertical.

  • When results are added the bar appears and looks to be working as expected.
  • If I scroll on the mouse it scrolls
  • But if I try to interact with the bar it does nothing.

The only thing I am doing that is a bit odd is setting select to entire row as when one is selected it causes a popup.

Also note this is a Outlook add in using C# and Net-office but that probably makes no difference.

Any ideas?

enter image description here

As you can see the populated grid shows the toolbar you just cant use it

Code for adding the rows to the datagrid

if (mailItem.Parent is Outlook.MAPIFolder)
{
  ParentFolder = mailItem.Parent as Outlook.MAPIFolder;
  ResultGrd.Rows.Add(mailItem.EntryID, ParentFolder.FolderPath, mailItem.SenderName, mailItem.Subject, mailItem.SentOn);
}

Generated code about the datagrid so you can see what all the settings are:

// 
// ResultGrd
// 
this.ResultGrd.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
| System.Windows.Forms.AnchorStyles.Left) 
| System.Windows.Forms.AnchorStyles.Right)));
this.ResultGrd.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells;
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
this.ResultGrd.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
this.ResultGrd.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.ResultGrd.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.ItemEntityID,
this.FolderH,
this.SenderH,
this.SubjectH,
this.DateH});
this.ResultGrd.Location = new System.Drawing.Point(13, 151);
this.ResultGrd.Name = "ResultGrd";
this.ResultGrd.ReadOnly = true;
this.ResultGrd.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.ResultGrd.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.ResultGrd.Size = new System.Drawing.Size(996, 381);
this.ResultGrd.TabIndex = 4;
this.ResultGrd.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick);
AndrewT
  • 468
  • 1
  • 8
  • 23
  • It looks like you will need to place the datagrid element within a containing element. See [here](http://stackoverflow.com/questions/673516/how-can-i-enable-scrollbars-on-the-wpf-datagrid) for more details. – CalebB Apr 16 '15 at 03:40
  • Thanks, but that looks to be another issue, as I stated above the scroll-bar is there so not missing it just doesn't do anything when I click on it or try to drag. The datagridview is all visible etc so not the issue referenced above. – AndrewT Apr 16 '15 at 03:45
  • Visible doesn't really mean much unfortunately so it being visible is not an argument for the scrollbar scrolling being enabled. As in scrollviewer you can have the scrollbar not visible at all and still scroll. Can you add some of your code? Not sure if you intended to do so but the image is cut off as well by the way. Also is this wpf or winforms? – CalebB Apr 16 '15 at 03:53
  • Yes winforms, also as the rows insert I see the normal srinnking of the part of the bar you grab. ALso as I scroll with the mouse wheel the bar moves as expected. – AndrewT Apr 16 '15 at 04:00
  • @caleb6 Thanks again for helping, I have cut the picture off as the results are real emails I don't want on the web. What code were you wanting to see. I have only set one attribute to make the bar appear, let me know what you want and I will post it. – AndrewT Apr 16 '15 at 04:02
  • 1
    Are you manually adding rows or you bind data source to datagridview? – Eplzong Apr 16 '15 at 05:43
  • I am looping through Outlook folder and adding information about mailitems as it matched the search criteria here is the code for the add 'ResultGrd.Rows.Add(mailItem.EntryID, ParentFolder.FolderPath, mailItem.SenderName, mailItem.Subject, mailItem.SentOn);' – AndrewT Apr 17 '15 at 00:54

0 Answers0