List View doesn't render items in Details view - winforms

VariableBox = gcnew ListView();
VariableBox->Font = ScriptEditorOptions->FontSelection->Font;
VariableBox->Dock = DockStyle::Fill;
VariableBox->BorderStyle = BorderStyle::Fixed3D;
VariableBox->BackColor = ScriptEditorOptions->BCDialog->Color;
VariableBox->ForeColor = ScriptEditorOptions->FCDialog->Color;
VariableBox->DoubleClick += gcnew EventHandler(this, &ScriptEditor::VariableBox_DoubleClick);
VariableBox->View = View::Details;
VariableBox->MultiSelect = false;
VariableBox->CheckBoxes = false;
VariableBox->FullRowSelect = true;
VariableBox->HideSelection = false;
VariableBox->Tag = (int)1;
ColumnHeader^ VariableBoxName = gcnew ColumnHeader();
VariableBoxName->Text = "Variable Name";
VariableBoxName->Width = 70;
ColumnHeader^ VariableBoxType = gcnew ColumnHeader();
VariableBoxType->Text = "Type";
VariableBoxType->Width = 50;
ColumnHeader^ VariableBoxIndex = gcnew ColumnHeader();
VariableBoxIndex->Text = "Index";
VariableBoxIndex->Width = 50;
VariableBox->Columns->Add(VariableBoxName);
VariableBox->Columns->Add(VariableBoxType);
VariableBox->Columns->Add(VariableBoxIndex);
VariableBox->ColumnClick += gcnew ColumnClickEventHandler(this, &ScriptEditor::VariableBox_ColumnClick);
I have the above code in a WinForms application. The control is added to the main form directly. For some reason, it never renders any items or columns when the layout is set to Details - Only the scroll bars are visible. The following code is used to add items to its collection:
ListViewItem^ Item = gcnew ListViewItem("Qw");
Item->SubItems->Add("Int");
Item->SubItems->Add("10");
VariableBox->Items->Add(Item);
Switching to any other view (at either run-time or design-time) fixes the issue. Any ideas on why this is happening ?
EDIT: Bump! Or is that not allowed ?

Turns out that I was removing the column headers before the control was displayed.

Related

ListView with only 1 column is not filling the whole width

I have a list view that gets populated dynamically each time a new message comes in. I did not add a column to the collection in the designer since I only need 1 column. But when the new message comes in, the "listview" gets populated but the single column is not taking the whole width of the listview.
lvRfidMessages.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
lvRfidMessages.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
string[] rowData = { e };
var lvItem = new ListViewItem(rowData);
lvRfidMessages.Items.Add(lvItem);
The design
this.lvRfidMessages.ForeColor = System.Drawing.Color.DimGray;
this.lvRfidMessages.FullRowSelect = true;
this.lvRfidMessages.GridLines = true;
this.lvRfidMessages.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.lvRfidMessages.HideSelection = false;
this.lvRfidMessages.Location = new System.Drawing.Point(0, 64);
this.lvRfidMessages.Name = "lvRfidMessages";
this.lvRfidMessages.Size = new System.Drawing.Size(182, 185);
this.lvRfidMessages.TabIndex = 3;
this.lvRfidMessages.UseCompatibleStateImageBehavior = false;

Resizing of an AutoScroll Panel affects scrolled position

When I resize the following form with the right resize handle, the contained TableLayoutPanel gets decorated with scroll bars (as intended, panel1.AutoScroll = true) for smaller form sizes, but the TableLayoutPanel also gets displaced from its original position. See images below: after resizing the form with right resize handle only, the second one has its scroll bars not leftmost and the left border of the content is cut off.
It seems somehow that this behavior is tied to the existence of the nested RadioButtons because if I remove them (or replace them by another TextBox for example), the "normal" behavior is restored (TableLayoutPanel stays in place during resize).
What properties do I have to set in order to keep the content always stationary relative to the (top)left borders?
BTW: When I replace the panel1 by a TabControl + one TabPage, the "normal" behavior is also restored.
using System;
using System.Drawing;
using System.Windows.Forms;
namespace Test
{
/// <summary>
/// Description of Form3.
/// </summary>
public partial class Form3 : Form
{
const int textBoxNameWidth = 500;
TableLayoutPanel testControl1;
Panel panel1;
TextBox textBoxName;
RadioButton radioButtonNo;
RadioButton radioButtonYes;
TableLayoutPanel tableLayoutPanelDecision;
public Form3()
{
testControl1 = new TableLayoutPanel();
panel1 = new Panel();
textBoxName = new TextBox();
radioButtonNo = new RadioButton();
radioButtonYes = new RadioButton();
tableLayoutPanelDecision = new TableLayoutPanel();
testControl1.AutoSize = true;
testControl1.AutoSizeMode = AutoSizeMode.GrowAndShrink;
testControl1.Location = new Point(0, 0);
testControl1.Dock = DockStyle.None;
testControl1.ColumnCount = 2;
testControl1.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
testControl1.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
testControl1.RowCount = 2;
testControl1.RowStyles.Add(new RowStyle(SizeType.AutoSize));
testControl1.RowStyles.Add(new RowStyle(SizeType.AutoSize));
testControl1.Controls.Add(textBoxName, 1, 0);
testControl1.Controls.Add(tableLayoutPanelDecision, 1, 1);
textBoxName.Text = "New Boolean";
textBoxName.TextAlign = HorizontalAlignment.Center;
textBoxName.Anchor = (AnchorStyles.Left | AnchorStyles.Right);
textBoxName.TabStop = false;
textBoxName.Width = textBoxNameWidth;
tableLayoutPanelDecision.AutoSize = true;
tableLayoutPanelDecision.ColumnCount = 2;
tableLayoutPanelDecision.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50f));
tableLayoutPanelDecision.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50f));
tableLayoutPanelDecision.RowCount = 1;
tableLayoutPanelDecision.RowStyles.Add(new RowStyle(SizeType.AutoSize));
tableLayoutPanelDecision.Controls.Add(radioButtonYes, 0, 0);
tableLayoutPanelDecision.Controls.Add(radioButtonNo, 1, 0);
tableLayoutPanelDecision.Dock = DockStyle.Fill;
radioButtonNo.Checked = true;
radioButtonNo.AutoSize = true;
radioButtonNo.TabIndex = 1;
radioButtonNo.TabStop = true;
radioButtonNo.Text = "False";
radioButtonNo.UseVisualStyleBackColor = true;
radioButtonNo.Anchor = AnchorStyles.None;
radioButtonYes.AutoSize = true;
radioButtonYes.TabIndex = 0;
radioButtonYes.Text = "True";
radioButtonYes.UseVisualStyleBackColor = true;
radioButtonYes.Anchor = AnchorStyles.None;
panel1.AutoScroll = true;
panel1.Controls.Add(testControl1);
panel1.Dock = System.Windows.Forms.DockStyle.Fill;
panel1.Location = new System.Drawing.Point(0, 0);
panel1.Name = "panel1";
panel1.Size = new System.Drawing.Size(560, 219);
panel1.TabIndex = 1;
AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
ClientSize = new System.Drawing.Size(560, 219);
Controls.Add(panel1);
Name = "Form3";
Text = "Form3";
}
}
}
The panel is trying to keep focusable controls within view for the user. To change that, you would have to use your own panel:
public class PanelEx : Panel {
protected override Point ScrollToControl(Control activeControl) {
return this.DisplayRectangle.Location;
}
}

Text Wrap not working for Telerik RadButtonElement

I am dynamically adding a button in Telerik RadListView. But the buttons are not wrapping the text.
Here is my code:
this.radBtnProduct = new RadButtonElement();
this.radBtnProduct.TextElement.Size = new Size(100,60); // .TextWrap = true;
this.radBtnProduct.Location = new Point(0, 0);
this.radBtnProduct.MinSize = new Size(100, 60);
this.radBtnProduct.MinSize = new Size(100, 60);
// wrapping
this.radBtnProduct.TextWrap = true;
Any help is appreciated
EDIT:
I used this code
this.radBtnProduct.Text = this.dataItem.Text.Replace(" ", "\n");
But am not sure if there are some issues with it
By default RadButtonElement has its AutoSize turned on. You need to switch it off in order to make your size work. Try this:
this.radBtnProduct = new RadButtonElement();
this.radBtnProduct.AutoSize = false;
this.radBtnProduct.Size = new Size(100, 60); // .TextWrap = true;
this.radBtnProduct.TextWrap = true;

Radiobuttons are invisible inside of Array of Panels

In the Form constructor I generate an array of panels (pnl_ in the code below), that include radiobuttons.
When I visualize the Form, only panels are visible, NOT radiobuttons inside.
Curiously, everything is OK, when I generate only one panel (pnl in the code below).
public partial class Radiobuttons_on_Panel : Form
{
private Panel pnl = new Panel();
private RadioButton rbtn1 = new RadioButton();
private RadioButton rbtn2 = new RadioButton();
private Panel[] pnl_ = new Panel[7];
private RadioButton[] rbtn1_ = new RadioButton[7];
private RadioButton[] rbtn2_ = new RadioButton[7];
public Radiobuttons_on_Panel()
{
InitializeComponent();
pnl.Location = new Point(10, 10);
pnl.Size = new Size(100, 100);
pnl.BorderStyle = BorderStyle.FixedSingle;
rbtn1.Location = pnl.Location;
rbtn1.Text = "AAA";
rbtn2.Location = new Point(pnl.Location.X, pnl.Location.Y + rbtn1.Height);
rbtn2.Text = "BBB";
pnl.Controls.Add(rbtn1);
pnl.Controls.Add(rbtn2);
this.Controls.Add(pnl);
for (int i = 0; i < pnl_.Length; i++)
{
pnl_[i] = new Panel();
pnl_[i].BorderStyle = BorderStyle.FixedSingle;
pnl_[i].Size = new Size(100, 100);
pnl_[i].Location = new Point(10 + i * 110, 200);
rbtn1_[i] = new RadioButton();
rbtn1_[i].Location = pnl_[i].Location;
rbtn1_[i].Text = "AAA";
rbtn2_[i] = new RadioButton();
rbtn2_[i].Location = new Point(pnl_[i].Location.X, pnl_[i].Location.Y + rbtn1_[i].Height);
rbtn2_[i].Text = "BBB";
pnl_[i].Controls.Add(rbtn1_[i]);
pnl_[i].Controls.Add(rbtn2_[i]);
this.Controls.Add(pnl_[i]);
}
}
}
Where is the problem?
Your problem with this is that your calculation of location is wrong. The location of the radio buttons are relative to their container - in this case, the panels. If you just set your locations to
rbtn1_[i] = new RadioButton();
rbtn1_[i].Location = new Point(10, 10);
rbtn1_[i].Text = "AAA";
rbtn2_[i] = new RadioButton();
rbtn2_[i].Location = new Point(rbtn1_[i].Location.X, rbtn1_[i].Location.Y + rbtn1_[i].Height);
rbtn2_[i].Text = "BBB";
the buttons will lay out like you want them to.
Thing work out in your first one because your radio button locations values are small enough to be visible in the panel. For those others, well, they are outside the bounds of their parent panels.
The long and short of it is that the Location property is always relative to the container, whether that is a Panel or a Form - the Location values for your panels are relative to the Form but the the Location values for your radio buttons are relative to whatever panel they are in.
MSDN Reference: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.location.aspx

wpf toolkit datagrid performance

i am porting my application from windows forms to WPF. I have found that datagrid is available only through the WPF Toolkit. However i have some issues with performance. This could be because something that performed alright in windows forms does not in wpf since it has to be implemented differently. Anyhow, i am doing something like this:
// XAML
<toolkit:DataGrid x:Name="dataGrid" ItemsSource="{Binding Path=.}"/>
// C#
DataTable dataTable = new DataTable();
MyViewModel viewModel = new MyViewModel();
this.dataGrid.AutoGenerateColumns = false;
this.dataGrid.CanUserAddRows = false;
this.dataGrid.CanUserDeleteRows = false;
this.dataGrid.CanUserReorderColumns = true;
this.dataGrid.CanUserResizeColumns = true;
this.dataGrid.CanUserResizeRows = false;
this.dataGrid.CanUserSortColumns = true;
this.dataGrid.IsReadOnly = true;
this.dataGrid.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
this.dataGrid.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
this.dataGrid.ColumnHeaderHeight = 18;
this.dataGrid.RowHeight = 18;
this.dataGrid.DataContext = vm.dataGrid;
List<string> s = new List<string>();
for (int i = 0; i < 80; ++i)
{
s.Add("col" + i);
}
for (int i = 0; i < s.Count; ++i)
{
dataTable.Columns.Add(new DataColumn(s[i], typeof(string)));
Binding items = new Binding();
PropertyPath path = new PropertyPath(dataTable.Columns[i].ColumnName);
items.Path = path;
DataGridColumn dc = new DataGridTextColumn()
{
Header = dataTable.Columns[i].ColumnName,
Width=70,
Binding = items
};
this.dataGrid.Columns.Add(dc);
}
viewModel.dataGrid = dataTable;
this.dataGrid.DataContext = viewModel.dataGrid;
for (int i = 0; i < 1000; ++i)
{
var row = dataTable.NewRow();
for (int j = 0; j < s.Count; ++j)
{
row[s[j]] = "text" + s[j] + j;
}
dataTable.Rows.Add(row);
}
The above is a sample of simply generating same number of columns by binding each header.
When this loads, i get all the elements displayed correctly, but scrolling is really slow. I know that someone might say that i am rendering 80 columns and 1000 elements, but i had more than 10000 displayed in my windows forms application and had no issues with it.
The only difference with Windows Forms is that instead of using Binding i was setting the dataGridView's dataSource to the DataTable each time i was updating it.
Any ideas? What am i doing wrong?
Try setting EnableRowVirtualization=True

Resources