|
Hello all, I am having a little trouble with a ListView. I am trying to update an item but it isn't doing what it should...
To explain: I have a list containing about 20 items. I can find the index location for the item I want to update. I am then removing the old item at the found index location, and then inserting the new item at the same point. It works, but with one problem...
It isn't inserting the new item at the correct index position. Instead it is putting it at the bottom of the list... And I can't work out why??
I am viewing the list in 'tile' view.
Can anybody help?
Thanks in advance,
Phil
"Rules are for the obedience of fools and the guidance of wise men"
|
|
|
|
|
Hello,
You tried already :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformslistviewlistviewitemcollectionclassinserttopic.asp
Creates a new item and inserts it into the collection at the specified index.
[C#] public ListViewItem Insert(int, string);
that doesn't work?
You have some code ?
|
|
|
|
|
Thanks for the reply...
I can insert the item. It is just not being inserted where I asked it to be...
Here is the code:
ListViewItem temp = new ListViewItem();<br />
temp = listView_main.FindItemWithText(item_text, true, 0);<br />
int location = temp.Index;<br />
<br />
ListViewItem lvItem = new ListViewItem(item_text, icon);<br />
lvItem.SubItems.Add("Name:" + name + "(" + aka + ")");<br />
lvItem.SubItems.Add("Data:" + data);<br />
lvItem.ToolTipText = item.ToString();<br />
lvItem.Group = listView_main.Groups[0];<br />
<br />
listView_main.Items.RemoveAt(location);<br />
<br />
listView_main.Items.Insert(location, lvItem);
Hope that helps...
Phil
"Rules are for the obedience of fools and the guidance of wise men"
|
|
|
|
|
namespace codepro
{
///
/// Zusammenfassung für Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ListView TheList;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.Button button1;
///
/// Erforderliche Designervariable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Erforderlich für die Windows Form-Designerunterstützung
//
InitializeComponent();
//
// TODO: Fügen Sie den Konstruktorcode nach dem Aufruf von InitializeComponent hinzu
//
}
///
/// Die verwendeten Ressourcen bereinigen.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Vom Windows Form-Designer generierter Code
///
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
///
private void InitializeComponent()
{
System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] {
"One",
"1.2.",
"1.3.",
"1.4."}, -1);
System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem(new string[] {
"Two",
"2.1.",
"2.2.",
"2.3."}, -1);
System.Windows.Forms.ListViewItem listViewItem3 = new System.Windows.Forms.ListViewItem(new string[] {
"Four",
"4.1.",
"4.2.",
"4.3."}, -1);
this.TheList = new System.Windows.Forms.ListView();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// TheList
//
this.TheList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2});
this.TheList.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
listViewItem1,
listViewItem2,
listViewItem3});
this.TheList.Location = new System.Drawing.Point(24, 16);
this.TheList.Name = "TheList";
this.TheList.Size = new System.Drawing.Size(200, 232);
this.TheList.TabIndex = 0;
this.TheList.View = System.Windows.Forms.View.List;
this.TheList.SelectedIndexChanged += new System.EventHandler(this.TheList_SelectedIndexChanged);
//
// columnHeader1
//
this.columnHeader1.Text = ":: 1 ::";
//
// columnHeader2
//
this.columnHeader2.Text = ":: 2 ::";
//
// button1
//
this.button1.Location = new System.Drawing.Point(240, 80);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(48, 64);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.button1);
this.Controls.Add(this.TheList);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
///
/// Der Haupteinstiegspunkt für die Anwendung.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void TheList_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
private void button1_Click(object sender, System.EventArgs e)
{
System.Windows.Forms.ListViewItem listViewItemIns = new System.Windows.Forms.ListViewItem(new string[] {
"Three",
"3.1.",
"3.2.",
"3.3."}, -1);
TheList.Items.Insert(2,listViewItemIns);
Refresh();
}
}
}
The button1_Click inserts the Item "Three" at the correct place
So i doesn't see a mistake in you code
|
|
|
|
|
I am using a textbox which takes date of birth as input
I want to use regular expression validator for that textbox
The Date Format Should Be mm/dd/yyyy
and valid date
Can Enyone Hel me Out
|
|
|
|
|
|
You can use a Masked Textbox?
|
|
|
|
|
If you want a regex the following should work
\d{2}/\d{2}/\d{4}
Not very advanced, just checks for 2 digits followed by a slash and 2 more digits, then a slash then a group of four digits.
Sig cops got me...
|
|
|
|
|
You can use a pattern like "\d{2}/\d{2}/\d{4}" to validate only the format. You can rule out dates that clearly are invalid with a pattern like "(0[1-9]|[12]\d|3[01])/(0[1-9]|1[0-2])/(19|20)\d\d", but a pattern that would actually check if the date is valid would be extremely complex. Just imagine all the combinations to validate the correct number of days in the different months, then imagine leap years on top of that...
---
b { font-weight: normal; }
|
|
|
|
|
If the regex isn't an absolute requirement, look into DateTime.TryParse()
|
|
|
|
|
Hi all,
I want an image button (ie, fully owner drawn) where the image has some transparancy.
The button sits on a form which has a custom OnPaint which draws to the form surface, the button lies on top. So, the transparant parts of the button should show the image on the form underneath.
In the constructor of my image button class, I set the styles UserPaint, AllPaintingInWmPaint, and DoubleBuffer.
In my OnPaint override, I simply draw the button.
But it doesn't work, the background behind the button is not what I drew on the form. In fact, it seems to be the image for the standard button toolbar (in blue). No idea why.
Anyone got any pointers?
Thanks
Jon
|
|
|
|
|
The problem with Transparency and controls is that it's NOT transparent. A control cannot be made to be fully transparent. Why? Well, because when the controls parent container paints it's background, it paints around the controls it contains, leaving holes (regions) in the background where the constituent controls will show up. It's up to the controls to paint themselves into those holes. All the controls know is that they have a surface to paint on. That surface is NOT part of the parent container!
Setting a controls BackColor to Transparent tells the control to take on the background of the parent container. It does not make the control transparent! The control simulates this transparency by using the BackColor and BackgroundImage properties of it's parent container, so it blends in with the background of the parent! The control knows nothing of other child controls in any parent container, or any grandparent container.
This means that if you put, say, two 2 button controls on the form and overlap them so one button is partially obscuring the other and you make the top button transparent, you will NOT see the remaining part of the covered button through the top button! You will see the background of the parent container both buttons sit in!
Try this... Drop a Panel control on a form, then either set it's background to a bitmap image and make sure it streches to fill the entire panel, or set it's backcolor to any color. Then drop a Label control on the Panel and make it take up about 1/4th the size of the Panel. Change it's BackColor to anything, except Transparent. Then drop another Label control on the Panel and position it so that one corner covers a corner of the other Label. Change it's BackColor to Transparent and watch what happens.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi. I am using visual studio 2005 with Sql Server Express Edition. I haven't install sql server 2005 Professional edition on my machine. It works fine. The connection string is:
<add name="RealEstateConnectionString" connectionstring="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\RealEstate.mdf;Integrated Security=True;User Instance=True" providername="System.Data.SqlClient">
You can see I haven't hardcoded machine name and there is no absolute path.
I have open the website on another machine and it works fine. Now , i have open this project on third machine but it doesn't work and gives the following error:
"An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"
I think there is some problem with sql server configuration . Please help me in this regards. I will be very thankful to you.
Fahim
Great Men always help people.
|
|
|
|
|
|
Has anyone encountered a message box that pops up behind the main form? How do I fix this?
private void button13_Click_1(object sender, EventArgs e)
{
item i = new item();
Button b = new Button();
b.Text = "hello";
b.Click += new EventHandler(b_Click);
subItem s = new subItem("hello");
s.EmbeddedControl = b;
i.SubItems.Add(s);
this.myListView1.Items.Add(i); //my custom windows control
}
void b_Click(object sender, EventArgs e)
{
MessageBox.Show(this, "hello");
//this is refering to the main form in here...
}
|
|
|
|
|
Hello,
Check if your mainform was set to "TopMost = true"
All the best,
Martin
|
|
|
|
|
|
Check the properties of your mainform and make sure that topmost is set to false.
|
|
|
|
|
|
I am trying to customize a commercial component.
I found I could write something like that:
public class MyHackClass : StupidCommercialClass
{
protected override void OnAnEvent()
{
if(!someCondition)
{
base.OnAnEvent();
return;
}
....
}
}
The problem is, I still want to raise the event 'AnEvent' but I do not want to call the base class's OnAnEvent() method.
Is there a way to achieve that with reflection?
As shown in the sample I already look (without much luck) into TypeDescriptor class..
|
|
|
|
|
Does this work?
if (this.AnEvent != null)
this.AnEvent(this, new EventArgs());
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Nope, only the declaring class could fire the event.
What I need is a way to get at the underlying storing delegate.
|
|
|
|
|
TypeDescriptor is for Design-Time support of components and not for Reflection purposes.
Use typeof(StupidCommercialClass).GetField(...).GetValue(..) to get the field storing the delegate - it should be a private field having exactly the same name as the event.
|
|
|
|
|
|
How to parse generic numeric string, irrespective of whether the enter value is small int (int16) or big int (int32) or more than that. I want to parse the string as numeric (number) not as int16 or int32?
Thanks in advance
kumar
|
|
|
|
|