|
if you expect some type you can try converting or parsing Text property of the textbox..
example:
bool success = false;
int outVal;
success = int.TryParse(Textbox.Text, out outVal);
if(success)return outVal;
and so on with other types..
life is study!!!
|
|
|
|
|
Good afternoon, I'm investigating about the ScrollBar and I have found some info that could be interesting, using a VisualStyleRenderer
VisualStyleRenderer render = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ThumbButtonVertical.Normal);
Rectangle thum_pos = render.GetBackgroundExtent(e.Graphics, vScrollBar1.Bounds);
Does anyone know how to get the Elements Position of a control using the VisualStyles and overpaint them?...
All info and links will be welcome.
Thanks everyone
|
|
|
|
|
Hello,
I am new to C# programming (day 1). I have created a list view object dynamically, and added 1000 items to it. Now I want to copy these objects to another list view, which wasn't dynamically created. But I do not see the contents to get coiped. The following is the corresponding code.
ListView lv = new ListView();
for (int i = 0; i < 1000; i++)
{
lv.Items.Add(new ListViewItem("Hi there"));
}
listView1 = lv; <font color=green>
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
you might need to call listView1.Refresh() after you assign lv to it
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Actually, I tried that before posting it. That doesn't help.
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
I thought that woulda worked (that or "Update()"). but it doesn't. When i debugged it i did see it get copied over though.
the only other thing that i can think of is something like this
ListView lv = new ListView();
lv.Items.Add(new ListViewItem("Hello"));
foreach (ListViewItem items in lv.Items)
{
ListViewItem lvItem = (ListViewItem)items.Clone();
listView1.Items.Add(lvItem);
}
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Thanks, that works! But loading items in the ListView becomes real slow if the no. of items become huge.
teejayem wrote: When i debugged it i did see it get copied over though.
If it gets copied over, is there any way I could refresh the state of it somehow, so that it reflects it in the UI too?
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
Hi,
adding them one by one causes a recalculation of the layout every time.
There are two ways to avoid this speed trap:
- add a range of items
- suspend and resume layout
See the corresponding ListView methods.
|
|
|
|
|
Luc Pattyn wrote: There are two ways to avoid this speed trap:
- add a range of items
- suspend and resume layout
Thank you very much Luc Pattyn. I will look into it. The speed trap was the actual problem.
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
Personally what i would have done is create a dataset object and go through each row of the dataset and add items to the listview if you'd like a snippet of that please let me know
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Please give me a snippet. That would help me.
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
DataSet ds = new DataSet();
ds.Tables.Add("Table 1");
ds.Tables[0].Columns.Add("Column 1");
ds.Tables[0].Rows.Add("Hello");
ds.Tables[0].Rows.Add("World");
foreach (DataRow row in ds.Tables[0].Rows)
listView1.Items.Add(row.ItemArray[0].ToString());
Hope this helps
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
What is that your trying to do? Why do you want to add it to one listview and again add it to another listview? You can use a listviewitem and add it to both the listview's if that is what your trying to do.
|
|
|
|
|
Tarakeshwar Reddy wrote: Why do you want to add it to one listview and again add it to another listview?
One is in the memory, and another is in the UI.
Tarakeshwar Reddy wrote: You can use a listviewitem and add it to both the listview's if that is what your trying to do.
No, I've added some items to a listview in the memory, and then I want all these items to be added to the one in the UI.
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
brahmma wrote: No, I've added some items to a listview in the memory, and then I want all these items to be added to the one in the UI.
But why would you want to do that? Is there a specific reason you want to have the items in the memory? You will have to add 1000 items in the listview object in memory and again re-add 1000 items to the listview in the UI, thats almost like adding 2000 items and that would surely slow down the app.
|
|
|
|
|
Doing stuff in the memory is certainly faster. And I was testing with it and trying to find out if there is a function that would update the status of a control. (UpdateData() , in MFC does that in both directions, between a control and a member variable).
Tarakeshwar Reddy wrote: You will have to add 1000 items in the listview object in memory and again re-add 1000 items to the listview in the UI, thats almost like adding 2000 items and that would surely slow down the app.
You see, I was trying to find out if I could copy a listview object in memory to another.
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
brahmma wrote: You see, I was trying to find out if I could copy a listview object in memory to another.
Yeah I did get that, but I am not sure if you can do that. You have an option to do an AddRange which would add a listview[], but I am not sure if that would be of any help to you either.
|
|
|
|
|
Hmm... Looks like I've done a bad start with C#.
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
brahmma wrote: One is in the memory, and another is in the UI.
so you have to add it twice. sure it will slow down the application.
Regards,
Satips.
|
|
|
|
|
I think you did not get it right. I wanted to know if I could copy an listview object (along with its status) to another listview object, one being in the memory and another one being in the UI.
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
oh.
Regards,
Satips.
|
|
|
|
|
brahmma wrote: listView1 = lv; //Can I equate it like this?
That line does not copy the contents, it just makes listView1 refer to whatever lv was referring to. After executing that statement, both listView1 and lv refer to the same object.
Taking a guess at why you don't see the list items in the UI, you probably added listView1 to the form's Control collection i.e
form.Controls.Add(listView1);
Making listView1 refer to another object by writing listView1 = lv will not change the ListView object in the Controls collection. You can see why if you think of listView1 and lv as pointers to ListView instances (which they are).
Hope this helps.
|
|
|
|
|
S. Senthil Kumar wrote: That line does not copy the contents, it just makes listView1 refer to whatever lv was referring to. After executing that statement, both listView1 and lv refer to the same object.
Thank you. That explained the problem.
S. Senthil Kumar wrote: Making listView1 refer to another object by writing listView1 = lv will not change the ListView object in the Controls collection.
How do I copy the state (list view items) of a ListView Object that I have in memory to the object pointed by listView1, which belongs to the Controls collection?
Actually, I am retrieving data from a database and populating a ListView object with it. The UI operation seems to be slow and so I thought I would do it in the memory, and copy all the contents at once. (I miss the UpdateData(false); here. I am an MFC programmer and forgive me if I sound stupid.
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
brahmma wrote: Actually, I am retrieving data from a database and populating a ListView object with it. The UI operation seems to be slow and so I thought I would do it in the memory
What exactly is the bottleneck, retrieiving data from the database or adding elements to the listview? If it's the former, you can use a separate thread to retrieve data and construct a list of ListViewItem and then use the UI thread to add the ListViewItem s to the ListView . Something like
ListView listView;
delegate void UpdateListViewDelegate(List<ListViewItem> listViewItems);
void DBDataLoaderThread()
{
List<ListViewItem> items = new List<ListViewItem>();
...
while (dataReader.Read())
{
items.Add(new ListViewItem(...));
}
listView.BeginInvoke(new UpdateListViewDelegate(UpdateListView), new object[] { items } );
}
void UpdateListView(List<ListViewItems> listViewItems)
{
foreach(ListViewItem item in listViewItems)
{
listView.Items.Add(item);
}
}
If it's the latter, you can use BeginUpdate</code. before starting to add elements to the <code>ListView and EndUpdate after it - this will prevent the ListView from repainting after adding each element.
void UpdateListView(List<ListViewItems> listViewItems)
{
listView.BeginUpdate();
foreach(ListViewItem item in listViewItems)
{
listView.Items.Add(item);
}
listView.EndUpdate();
}
|
|
|
|
|
S. Senthil Kumar wrote: If it's the latter, you can use BeginUpdateListView and EndUpdate after it - this will prevent the ListView from repainting after adding each element.
Heartfelt thanks. That is what I needed.
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|