|
Binding to list box
public List<string> Data
{
get
{
return this.data;
}
set
{
if (this.data != value)
{
this.data = value;
this.lboxEntries.DataSource = value;
}
}
}
BindingContext[] is built in part of the CurrencyManager which Forms/Controls have.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Sorry for the brevity of my last reply but I was half way through preparing my Dinner.
More context.
This is a UserControl containing a ListBox , a TextBox and three Button s (Add, Edit, Delete)
When user selects an item in the ListBox it is copied to the TextBox where they can edit it and hit Edit button to change content of LB. Replace text in TextBox hit Add button to add new text to LB. Hit Delete deletes all selected items from LB
private List<string> data;
private bool adding = false;
public EntryEditor()
{
InitializeComponent();
}
private void RefreshDataBoundControls()
{
CurrencyManager cm = (CurrencyManager)BindingContext[this.data];
cm.Refresh();
}
#region EntryEditor PROPERTIES .........................................
public List<string> Data
{
get
{
return this.data;
}
set
{
if (this.data != value)
{
this.data = value;
this.lboxEntries.DataSource = value;
}
}
}
#endregion
private void lboxEntries_SelectedValueChanged(object sender, EventArgs e)
{
this.btnEdit.Enabled = false;
this.btnDelete.Enabled = false;
if (!this.adding)
{
this.txtEditEntry.Text = "";
}
switch (this.lboxEntries.SelectedItems.Count)
{
case 0:
break;
case 1:
if (this.lboxEntries.SelectedIndex >= 0)
{
this.txtEditEntry.Text = this.lboxEntries.SelectedValue.ToString();
this.btnEdit.Enabled = true;
this.btnDelete.Enabled = true;
}
break;
default:
this.btnDelete.Enabled = true;
break;
}
}
private void btnEdit_Click(object sender, EventArgs e)
{
this.data[this.lboxEntries.SelectedIndex] = this.txtEditEntry.Text;
RefreshDataBoundControls();
}
private void btnDelete_Click(object sender, EventArgs e)
{
string[] selectedItems = new string[this.lboxEntries.SelectedItems.Count];
this.lboxEntries.SelectedItems.CopyTo(selectedItems, 0);
foreach (string s in selectedItems)
{
this.data.Remove(s);
RefreshDataBoundControls();
}
}
private void btnAdd_Click(object sender, EventArgs e)
{
this.adding = true;
try
{
this.lboxEntries.ClearSelected();
this.lboxEntries.Update();
this.data.Add(this.txtEditEntry.Text);
RefreshDataBoundControls();
this.lboxEntries.SelectedIndex = data.Count - 1;
}
finally
{
this.adding = false;
}
}
}
btnAdd_Click is the problem area.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Problem resolved.
Modified the order of code in btnAdd_Click .
this.data.Add(this.txtEditEntry.Text);
RefreshDataBoundControls();
this.lboxEntries.ClearSelected(); <============== Moved
this.lboxEntries.Update(); <===================== Moved
this.lboxEntries.SelectedIndex = data.Count - 1;
Thanks for the help.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Nice. I'm still not sure how it all works, and why it did what it did, and doesn't any more.
What would be wrong with:
this.data.Add(this.txtEditEntry.Text);
this.lboxEntries.ClearSelected();
this.lboxEntries.SelectedIndex = data.Count - 1;
?
1. if RefreshDataBoundControls is repopulating the ListBox, the added line should be gone? and if it isn't, what *is* it doing?
2. the Update() only has a visual effect, it should be all right as soon as your current handler is done anyway.
I'm going to investigate later, I'm off now.
|
|
|
|
|
Without the RefreshDataBoundControls() , the new item is not added to the LB.Items therefore it cannot be selected and the last line (of your snippet) throws an ArgumentOutOfRangeException
Agree about the Update() part. I didn't have that originally, added in an attempt to 'force' a redraw to get rid of the persistent highlight(s), and forgot to remove it.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
My mistake. The new line is added to data, not to the ListBox.
|
|
|
|
|
OriginalGriff wrote: What are you doing that is so different?
See my reply to Luc below.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
i am having a like this
Name -Nikhil Bhivgade
Class-6th
-------------------------------------
1 English 100 50 Pass
2 Maths 100 50 Pass
3 Science 100 20 Fail
4 History 100 20 Fail
--------------------------------------
in report footer i want to display failed subject Sr.No and Name
you Failed in 3.Science,4.History
|
|
|
|
|
Use a global variable. Global variable is visible for all the sections of the report. String Append Sr.No and Name of the subject based the status pass or fail.
The formula can be:
FormulaA : [Used in the PageHeader][Display of Formula Suppressed]
Global stringvar FailedDetails;
FailedDetails = "";
FormulaB: [Used in Detail Section][Display of Formula Suppressed]
Global stringvar FailedDetails;
WhileReadingRecords;
if (status = "fail")
FailedDetails = FailedDetails + SrNo + " " + Subject
FormulaC: [Used in Footer Section] [Display of Formula Not Sppressed]
Global stringvar FailedDetails;
FailedDetails;
For more information: Search in google with the keyword - "WhileReadingRecords" and "WhilePrintingRecords"
The above formula do not work by copy paste. You need to make some adjustment based on the Syntax.
Hope it Helps
|
|
|
|
|
It is returning me false
any suggestion
|
|
|
|
|
Hi All,
3 months ago i developed a WPF Application offline,and now i need to host this Application online.
This app gets the function to Add,Edit,Delete,Search (and so on ...) records in the database so it use a Databinding and now i need to host it online so the client can connect on the web to insert or update the data .
Can you suggest me which way is the best to host my App online using the Databinding?
Thanks so much for your attention.
..if you need more details don't hesitate to ask me .
Cheers
|
|
|
|
|
You should take a look at Silverlight[^].
You will obviously have to re-write some of your code, but if you app is already designed as a client/sever app you may find you are able to keep large parts of it. Silverlight at least uses a variant of XAML, so you may be able to reuse some of your GUI code.
You could also consider an XMAL Browser application[^], but you will find your platforms are more restricted to IE & Firefox only and Windows only.
Simon
|
|
|
|
|
WPF apps don't run in a browser. However, Silverlight is a subset of WPF, and most of your stuff should workk with little/no change with the possible exception of database access. Silverlight REQUIRES the use of a web service to access a database, even if the database in question is on the same server as the web server.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
You could use Silverlight like the other two answers told you, or you could use Click-Once deployment to deploy your WPF app.
|
|
|
|
|
Nishant Sivakumar wrote: Click-Once deployment to
He's talking about deploying on a web server - not about deployment in general.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
Abhinav S wrote: He's talking about deploying on a web server - not about deployment in general.
Click-Once apps are typically deployed on a web-server and accessed via an Http URL.
|
|
|
|
|
You can actually have a look at WPF XBAP applications[^].
XBAP files can be deployed on a web server and run in a web browser.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
Well,
firstly thanks so much for your good answers,
my app is very big there are also many Roles ,i like develop it with Silverlight but i am afraid i need time to do that as i have not a good experience,so i am researching also on the web to convert"WPF to Silverlight" .
I am looking also WPF XBAP applications[^] because it is would be simple and faster but a doubt born is my self if it can support all the features of my App.
Thanks so much for your support.
Have a good time.
Cheers
|
|
|
|
|
I have to Find Gridview Footer Row in Javascript. Is there any chance to show/hide footer row in javascript.
How to Find Label in Footer Row.
|
|
|
|
|
|
Sorry mate - wrong forum.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
Hi to all,
I have a page where I can add comments.
But after adding the comment,some data in the page goes missing.
Only if we refresh manually,we can see the data properly.
Does anyone have any suggestion for this?
The query is returning properly.
Regards,
Juman
|
|
|
|
|
Try this link
Don't forget to rate answer, that helped you. It will allow other people find their answers faster.
|
|
|
|
|
Sorry,I din't understand what you meant by that?
|
|
|
|
|
I mean this is ASP.NET question. Not C#.
Don't forget to rate answer, that helped you. It will allow other people find their answers faster.
|
|
|
|