ListView adding an empty colomn - c#

I have my listView in C#. It should have only one colomn, and also the attribute fo Colomns shows it has only one colomn, but the display shows two:
The ListView is initiated very simply, using
initializeComponenet()
which contains following code:
**this.lstDS.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.DirectoryHeader});**
this.lstDS.Font = new System.Drawing.Font("Microsoft Sans Serif", 12.75F);
this.lstDS.ForeColor = System.Drawing.Color.White;
this.lstDS.FullRowSelect = true;
this.lstDS.HideSelection = false;
this.lstDS.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
listViewItem1,
listViewItem2});
this.lstDS.Location = new System.Drawing.Point(75, 152);
this.lstDS.MultiSelect = false;
this.lstDS.Name = "lstDS";
this.lstDS.Size = new System.Drawing.Size(203, 138);
this.lstDS.TabIndex = 37;
this.lstDS.UseCompatibleStateImageBehavior = false;
this.lstDS.View = System.Window
if you ask yourself - here's DirectoryHeader:
private ColumnHeader DirectoryHeader;
But for any reason, it appears as if it has 2 columns.
Any idea what to check?
Thanks!

Related

c# Help creating a new tab with new rdp session in side of it

Any advice greatly appreciated.
I'm trying to dynamically create a tab, and inside of that tab, create a new rdp control.
I've got the tab creation fine. The RDP session seems like it's running through the code, but it never renders anything on the screen and never errors out.
I have the tab presented, but with no content.
Thanks.
TabPage myTabPage = new TabPage(tabtitle);
tabControl1.TabPages.Add(myTabPage);
AxMsTscAxNotSafeForScripting rdp4 = new AxMSTSCLib.AxMsTscAxNotSafeForScripting();
((System.ComponentModel.ISupportInitialize)(rdp4)).BeginInit();
rdp4.CreateControl();
myTabPage.Controls.Add(rdp4);
rdp4.Dock = System.Windows.Forms.DockStyle.Fill;
rdp4.Enabled = true;
rdp4.Location = new System.Drawing.Point(3, 3);
rdp4.Name= targetdevice;
rdp4.OcxState = ((System.Windows.Forms.AxHost.State)(new ComponentResourceManager(typeof(Form1)).GetObject("rdp4.OcxState")));
rdp4.Size = new System.Drawing.Size(574, 529);
rdp4.TabIndex = 0;
var settings = (MSTSCLib.IMsRdpClientAdvancedSettings8)rdp4.AdvancedSettings;
settings.allowBackgroundInput = 1;
settings.ClientProtocolSpec = MSTSCLib.ClientSpec.FullMode;
settings.ConnectToServerConsole = true;
settings.EnableCredSspSupport = true;
settings.EncryptionEnabled = 1;
settings.SmartSizing = true;
rdp4.DesktopHeight = 768;
rdp4.DesktopWidth = 1366;
rdp4.Server = targetdevice;
rdp4.UserName = txt_user.Text;
IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp4.GetOcx();
secured.ClearTextPassword = txt_password.Text;
rdp4.Connect();
tabControl1.SelectedTab = myTabPage;

Add a custom made component to a datagridview column

I need to add a custom built component to a column in datagridview. As far as I know, I can add buttons textboxes using the code below:
DataGridViewButtonColumn buttons = new DataGridViewButtonColumn();
{
buttons.HeaderText = "Move Up";
buttons.Text = "⇧";
buttons.UseColumnTextForButtonValue = true;
buttons.AutoSizeMode =
DataGridViewAutoSizeColumnMode.AllCells;
buttons.FlatStyle = FlatStyle.Standard;
buttons.CellTemplate.Style.ForeColor = Color.Black;
buttons.DisplayIndex = 3;
buttons.Width = 60;
}
Is there any way that I can add a custom built component to a column?

C# System.Windows.Forms.DataGridView vertical scroll is visible but cannot be used

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

C# - I can't make my rowheader invisible with DataGridTableStyle

When I used a DataGridTableStyle to format my Datagrid, the
RowHeadersVisible stopped working, then I saw on the internet I
should use the DataGrid.RowHeadersVisible, and then I tried, but it
says there's no such method. What could be wrong ?
I'm using .net compact framework 3.5, could this be the problem ? If
this method isn't avaiable, is there another way I could make the row
header of my grid invisible ?
This is my code:
dataGrid1.DataSource = tabela;
DataGridTableStyle ts = new DataGridTableStyle();
ts.MappingName = tabela.TableName;
DataGridColumnStyle celId = new DataGridTextBoxColumn();
DataGridColumnStyle celQuantitem = new DataGridTextBoxColumn();
celId.MappingName = "PRODUTOID";
celId.HeaderText = "Id";
celQuantitem.MappingName = "QUANTITEMSEPARADO";
celQuantitem.HeaderText = "Separado";
celId.Width = 50;
celQuantitem.Width = 75;
ts.GridColumnStyles.Add(celId);
ts.GridColumnStyles.Add(celQuantitem);
ts.RowHeadersVisible = false;
dataGrid1.TableStyles.Add(ts);
To hide the row headers of a compact framework DataGrid just use:
dataGrid1.RowHeadersVisible = false;
DataGridTableStyles.RowHeadersVisible is not supported.

Applying a filter to a BindingSource, but it doesn't work

I have a TextBox, in which I put a phrase, which is either the description of a task or the id of a task. I want to filter a list using the text from this TextBox. But when I put text into this TextBox, filtering doesn't work, and the collection in the DataGridView doesn't change.
What can be wrong?
public void BindData()
{
var emptyBindingSource = new BindingSource();
dataGridViewTaskList.AutoGenerateColumns = false;
dataGridViewTaskList.DataSource = emptyBindingSource;
var taskList = GetTasks();
_bindingSource = new BindingSource();
_bindingSource.DataSource=taskList.Response;
dataGridViewTaskList.AutoGenerateColumns = false;
dataGridViewTaskList.DataSource = _bindingSource.DataSource;
if (dataGridViewTaskList.Columns["gridViewColumnId"] == null)
dataGridViewTaskList.Columns.Add(new DataGridViewColumn() {Name = "gridViewColumnId"});
else
dataGridViewTaskList.Columns["gridViewColumnId"].DataPropertyName = "Id";
if (dataGridViewTaskList.Columns["gridViewColumnDescription"] == null)
dataGridViewTaskList.Columns.Add(new DataGridViewColumn() {Name = "gridViewColumnDescription"});
else
dataGridViewTaskList.Columns["gridViewColumnDescription"].DataPropertyName = "Description";
}
private void tbSearchedPhraseOrId_TextChanged(object sender, EventArgs e)
{
_bindingSource.Filter = string.Format("Id = '{0}'", tbSearchedPhraseOrId.Text);
}
I added the following in BindData method and it doesn't work either:
_bindingSource.Filter = string.Format("Id LIKE '%{0}%'", "23");
Designer:
this.dataGridViewTaskList.AllowUserToAddRows = false;
this.dataGridViewTaskList.AllowUserToDeleteRows = false;
this.dataGridViewTaskList.AllowUserToOrderColumns = true;
this.dataGridViewTaskList.AllowUserToResizeRows = false;
this.dataGridViewTaskList.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.dataGridViewTaskList.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
this.dataGridViewTaskList.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.dataGridViewTaskList.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridViewTaskList.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.gridViewColumnId,
this.gridViewColumnDescription});
this.dataGridViewTaskList.Location = new System.Drawing.Point(6, 62);
this.dataGridViewTaskList.MultiSelect = false;
this.dataGridViewTaskList.Name = "dataGridViewTaskList";
this.dataGridViewTaskList.ReadOnly = true;
this.dataGridViewTaskList.RowHeadersVisible = false;
this.dataGridViewTaskList.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dataGridViewTaskList.Size = new System.Drawing.Size(414, 488);
this.dataGridViewTaskList.TabIndex = 0;
According to the documentation, your underlying data source (i.e. your task list) must implement the IBindingListView interface to have a working Filter property. Are you sure this is the case right now?
(As an aside, you should set the DataSource property of your DataGridView to the BindingSource object itself rather than the BindingSource.DataSource property.)
You can always check _bindingSource.SupportsFiltering
to see if the BindingSource type supports filtering
You should change:
dataGridViewTaskList.DataSource = _bindingSource.DataSource;
to
dataGridViewTaskList.DataSource = _bindingSource;
By changing _bindingSource.Filter you're not actualy changing _bindingSource.DataSource - it stays the same and because of that dataGridViewTaskList.DataSource doesn't change either. In the other hand, _bindingSource is changed, and you can bind directly to it to get that change.
Did you try with:
_bindingSource.Filter = string.Format("gridViewColumnId = '{0}'", tbSearchedPhraseOrId.Text);
Can you define taskList structure?
Try to call : _bindingSource.ResetBindings(false); after setting filter.
Also you can try to call:
dataGridViewTaskList.ResetBindings();
dataGridViewTaskList.Refresh();
dataGridViewTaskList.Update();
Alternative
IEnumerable, List.....etc Global Variable
listBindingSource.DataSource = List();
Then simple filter the list and Re-assign it
listBindingSource.DataSource = List.FindAll(t => t.x == yourValue);

Categories

Resources