|
BoneSoft wrote: Color is a struct and therefore mutable,
You're correct in this case (if you prepend "im" to the word "mutable"), but structs in general are not necessarily immutable. Immutability of structs is a best practice, not a rule.
:josh:
My WPF Blog[^]
|
|
|
|
|
Woops! My intellisence ain't working today. Thanks for catching that.
And my understanding was that all structs are immutable, trying to change them just creates and swaps a new one behind the scenes, like strings or any other stacked value. So they seem to be mutable, though technically they are not. Maybe I have it wrong...
Try code model generation tools at BoneSoft.com.
|
|
|
|
|
BoneSoft wrote: And my understanding was that all structs are immutable, trying to change them just creates and swaps a new one behind the scenes, like strings or any other stacked value
Structs (aka 'value types') are copied by reference, but that doesn't imply immutability.
This code creates a Point struct and modifies it (not a copy of it):
Point pt = new Point(1,1);
pt.X = 2;
:josh:
My WPF Blog[^]
|
|
|
|
|
Can you group together CheckBoxes so only one in a group is checked at one time and if so How?
|
|
|
|
|
Winforms or ASP.NET?
If Winforms:
Use RadioButtons instead of CheckBoxs. Put them in a GroupBox or Panel and they'll automatically be mutually exclusive.
:josh:
My WPF Blog[^]
|
|
|
|
|
Winforms, and i can't use Radion buttons because i am looking for the sticky button look that a check box has.
|
|
|
|
|
Your users will be confused by mutually exclusive checkboxes. It's atypical and, hence, weird. When it comes to UIs, stick to conventions unless you have a very good reason not to.
:josh:
My WPF Blog[^]
|
|
|
|
|
What the hell is "sticky button look"? Can I use that next time I'm at the pool?
Try code model generation tools at BoneSoft.com.
|
|
|
|
|
You deserve to be thrown off a cliff for doing so. Check box are designed so you can select multiple. Options are designed to choose. Switching the two will only confuse people.
That said, create a collection of all of the check boxes you want to enforce one check only. Add a listener to all the check boxes for CheckedChanged to the same method. In the method loop through all of the check boxes in the collection if the sender object is a check box that is true and set all other check boxes to unchecked.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
private void checkBox_CheckedChanged(object sender, EventArgs e) {
if(sender is CheckBox){
if(((CheckBox)sender).Checked){
foreach(CheckBox ck in list){
if(ck != sender){
ck.Checked = false;
}
}
}
}
}
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
LMAO my bad, I'm sorry thanks for the help though sounds like a good solution
|
|
|
|
|
I have a centralcserver that receives SNMP traps for a number of other devices within a very large network (6000+ trap generating devices).
I need to find a mechanism that will allow me to decode the raw SNMP data into something that is human readable.
Does anybody know of any C# based libraries that are capable of doing this?
|
|
|
|
|
|
Read the textbook again or audit the class
|
|
|
|
|
Try this one:
StreamReader s = new StreamReader(@"f:\mytext.txt");
ArrayList a = new ArrayList();
while (s.Peek() >= 0)
{
string alltext = "";
string text = "";
while ((text = s.ReadLine()) != "" && text != null)
{
alltext += ("|" + text);
}
a.Add(alltext);
}
s.Close();
foreach (string text in a)
{
string[] splitString = text.Split('|');
string tempstring = "";
for (int i = 3; i < splitString.Length; i++)
{
tempstring += splitString[i];
}
ListViewItem lvi = new ListViewItem(new string[] { splitString[1], splitString[2].Substring(0, 12), splitString[2].Substring(17, 12), tempstring });
this.listView1.Items.Add(lvi);
}
|
|
|
|
|
Wow, nothing like doin' his classwork for him. Now he'll definately fail the class!
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi
I want to take the value of a datagrid cell and by drag and drop put it in other cell inside the same datagrid. Anybody knows hot to do this?
Thank you
Kenneth Mora Flores
|
|
|
|
|
Dear friends...
There are 3 tables in my database which 2 of them are related as parent and child. And here are the columns:
Parent Table: ParentCode int(PK), ParentName nvarchar(256)
Child Table: ChildCode int(PK), ChildName nvarchar(256), ParentCode int(FK)
3rd Table(MyTable): SerialNumber int(PK), Name nvarchar(256), Parent int, Child int
These 3 tables are loaded into a dataset with the specified relation named 'ParentChild'.I want to store SelectedValue of comboboxes into the 'MyTable'. Two comboboxes are placed on my form with following bindings:
comboBoxParent.DataSource = dataSet;<br />
comboBoxParent.DisplayMember = "Parent.ParentName";<br />
comboBoxParent.ValueMember = "Parent.ParentCode";<br />
comboBoxParent.DataBindings.Add("SelectedValue",dataSet.Tables["MyTable"],"Parent");<br />
<br />
comboBoxChild.DataSource = dataSet;<br />
comboBoxChild.DisplayMember = "Parent.ParentChild.ChildName";<br />
comboBoxChild.ValueMember = "Parent.ParentChild.ChildCode";<br />
comboBoxChild.DataBindings.Add("SelectedValue",dataSet.Tables["MyTable"],"Child");
Note that there is no relation between MyTable and other two tables (Parent and Child).
When SelectedIndex of the parent combo is changed, child combo changes respectively but SelectedIndexChanged, SelectedValueChanged, ... of the child combo doesn't fire! SelectedValue of the child combo is changing but due to events stoppage the underlying datasource can't be aware of changes and doesn't update itself. When I press the update button or I change the bindingsource position the SelectedValue of child combo becomes null.
On Update button click I write the following code :
this.BindingContext[dataSet.Tables["MyTable"]].EndCurrentEdit();<br />
myDataAdapter.Fill();
Please guide me ! I think this is a bug of List controls or data binding of .NET !
[ _ Always there is another way _ ]
|
|
|
|
|
Hi,
can anyone tell me how to change a text file in C.
arun
|
|
|
|
|
Do you mean C# ? System.IO.File is what you need, in .NET 2.0 there are static methods to read all the text out of a file, and write all text back to a file, so you can read it, modify it, and write it back out.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I have an asp.net application. User enters some data into some text fields and such and clicks a button. The button runs a stored procedure. The stored procedure returns an ID number that I need to use in subsequent pages. Within the section that runs the stored procedure, the ID (called IDOutput2) retains its value. However, when I try to access it outside the function, I lose its value. I thought I had declared everything properly, but obviously I'm missing something.
public object IDOutput2;<br />
.<br />
.<br />
.<br />
public void btnAdd_Click(object sender, System.EventArgs e)<br />
{<br />
strPartNumberInputReference = txtSearchPart.Text;<br />
strPartTypeID = ddPartType.SelectedValue;<br />
strDwgNumber = txtDwgNumber.Text;<br />
strDwgRevision = txtDwgRevision.Text;<br />
strDwgLocation = txtDwgLocation.Text; <br />
SqlParameter param1 = new SqlParameter("@PartNumber", strPartNumberInputReference); <br />
SqlParameter param2 = new SqlParameter("@PartTypeValue", strPartTypeID);<br />
SqlParameter param3 = new SqlParameter("@ID", SqlDbType.Int);<br />
param3.Direction = ParameterDirection.Output;<br />
try<br />
{<br />
IDOutput = SqlHelper.ExecuteNonQuery (this.connectionString, CommandType.StoredProcedure, "dbo.UpdatePart_Step_1", param1, param2, param3);<br />
IDOutput2 = param3.Value;<br />
SqlParameter param4 = new SqlParameter("@DwgRevision", strDwgRevision);<br />
SqlParameter param5 = new SqlParameter("@DwgNumber", strDwgNumber);<br />
SqlParameter param6 = new SqlParameter("@DwgLocation", strDwgLocation);<br />
SqlParameter param7 = new SqlParameter("@ID2", IDOutput2);<br />
IDOutput = SqlHelper.ExecuteNonQuery (this.connectionString, CommandType.StoredProcedure, "dbo.UpdatePart_Step_1_part2", param4, param5, param6, param7);<br />
Response.Write ("Successful update.");<br />
txtSearchPart.Text = "";<br />
txtDwgNumber.Text = "";<br />
txtDwgLocation.Text = "";<br />
txtDwgRevision.Text = "";<br />
ddPartType.SelectedIndex = 1;<br />
Response.Write (IDOutput2);<br />
}<br />
<br />
catch<br />
{<br />
Response.Write ("Insert failed.");<br />
}<br />
<br />
}
I tried changing the function to:public object btnAdd_Click(object sender, System.EventArgs e) and do a return IDOutput2 but I got the error that not all paths return a value.
How do I fix this?
|
|
|
|
|
You cannot change the signature of an event, and if you did, where would you expect the ID to return to ?
You need to store the ID somewhere. The easiest way is to put it on the URL, but if you want to hide it, it needs to go into the session or into a database that you can access using a session ID between pages. Does it run on a web farm, or a single server ? Session state is no good for web farms.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Singe server so that's not a problem.
After the Add_Click event the user will hit a button to go to the next web page. I have the following:
private void btnGo2Weights_Click(object sender, System.EventArgs e)<br />
{<br />
Response.Redirect ("Add_Weight.aspx?IDOutput2=&strPartNumberInputReference=" +IDOutput2 + strPartNumberInputReference);<br />
<br />
}
I tried dumping out the IDOutput2 and it's blank.
Hiding is not an issue.
So basically I can access IDOutput2 in btnAdd_Click but nowhere else.
|
|
|
|
|
The problem is not that you can't access the variable outside the method, because you can.
The problem is that the instance of the page class where the value was, doesn't exist any more.
The instance of the page class where you stored the value in the IDOutput2 variable is used to create the page that is the response to that request. When that page has been created, the instance of the page class containing that value is released.
When the user clicks the button to go to the next page, a new instance of the page class is created to handle that request. As it is a new instance, you haven't assigned any value to the IDOutput2 variable in that instance.
The value doesn't magically reappear in the variable, just because it previously existed in a different instance of the same class.
---
b { font-weight: normal; }
|
|
|
|
|
Thanks for the explanation, Guffa. That really did help me understand it better.
To get around it in the meantime I did a session:
public void btnAdd_Click(object sender, System.EventArgs e)<br />
{<br />
strPartNumberInputReference = txtSearchPart.Text;<br />
strPartTypeID = ddPartType.SelectedValue;<br />
strDwgNumber = txtDwgNumber.Text;<br />
strDwgRevision = txtDwgRevision.Text;<br />
strDwgLocation = txtDwgLocation.Text; <br />
SqlParameter param1 = new SqlParameter("@PartNumber", strPartNumberInputReference); <br />
SqlParameter param2 = new SqlParameter("@PartTypeValue", strPartTypeID);<br />
SqlParameter param3 = new SqlParameter("@ID", SqlDbType.Int);<br />
param3.Direction = ParameterDirection.Output;<br />
try<br />
{<br />
IDOutput = SqlHelper.ExecuteNonQuery (this.connectionString, CommandType.StoredProcedure, "dbo.UpdatePart_Step_1", param1, param2, param3);<br />
IDOutput2 = param3.Value;<br />
SqlParameter param4 = new SqlParameter("@DwgRevision", strDwgRevision);<br />
SqlParameter param5 = new SqlParameter("@DwgNumber", strDwgNumber);<br />
SqlParameter param6 = new SqlParameter("@DwgLocation", strDwgLocation);<br />
SqlParameter param7 = new SqlParameter("@ID2", IDOutput2);<br />
IDOutput = SqlHelper.ExecuteNonQuery (this.connectionString, CommandType.StoredProcedure, "dbo.UpdatePart_Step_1_part2", param4, param5, param6, param7);<br />
Response.Write ("Successful update.");<br />
txtSearchPart.Text = "";<br />
txtDwgNumber.Text = "";<br />
txtDwgLocation.Text = "";<br />
txtDwgRevision.Text = "";<br />
ddPartType.SelectedIndex = 1;<br />
Response.Write (IDOutput2);<br />
Session["number"] = IDOutput2; Session["strPartNumberInputReference"] = strPartNumberInputReference;<br />
<br />
}<br />
<br />
catch<br />
{<br />
Response.Write ("Insert failed.");<br />
}<br />
}
Then called the session on pageload
private void Page_Load(object sender, System.EventArgs e)<br />
{<br />
IDOutput3 = Session["number"];<br />
if(Page.IsPostBack)<br />
{<br />
BindData(); <br />
.<br />
.<br />
.
Is there a different way (a better way) to do this that would be considered a best practice?
|
|
|
|
|