|
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?
|
|
|
|
|
What's best depends on what you need. An alternative could be to put the value in a hidden field, then the value will be posted back to the server in the next postback.
If you use a session variable, you depend on the session to still be active. If the user waits for more than 20 minutes (default setting) before pressing the second button, the session will have timed out, and the session variable is gone with it.
---
b { font-weight: normal; }
|
|
|
|
|
The voyage continues.
I read Graus's reply, so I won't touch on what he said.
To answer your question of why you get the compiler error: Cuz your method isn't returning a value from all logical exit points. You were only returning a value at the bottom of the try block. What if an exception was thrown? Where would the return value come from then? (Note, you can't modify an event handler's signature anyways. You aren't calling your event handler are you? Is that why you added a return value? Very bad practice. Naughty. Bad Leckey, bad!)
:josh:
My WPF Blog[^]
|
|
|
|
|
Josh Smith wrote: You were only returning a value at the bottom of the try block.
Yeah, I figured out that one after I made the post.
Josh Smith wrote: can't modify an event handler's signature anywa
Graus mentioned that, too.
So how do I actually fix this so I can access the value outside of btnAdd_Click?
|
|
|
|
|
leckey wrote: So how do I actually fix this so I can access the value outside of btnAdd_Click?
I'm not an ASP.NET dev, but from what I remember...if you need to access a value across postbacks you should store it in a persistence medium, such as session state. If you only need it within a Page instance during one postback, you can store it as an instance member field in the Page-derived class and, optionally, expose it as a property on the class so that other pages can access it.
:josh:
My WPF Blog[^]
|
|
|
|
|
Hello,
can someone told me how to implement such a structure:
ObjectA1
| |
| |-ObjectB1
| | |
| | ObjectC2
| | ObjectC3
| |
| |-ObjectB2
| |
| ObjectD1
|
|
|
ObjectC4
Maybe somebody knows a tutorial or a litte code example ?
Thank you for your help,
Chris
|
|
|
|
|
What do you want to do here, create a data structure ? Obviously, what you need is a system where each item knows what it's parent is. The easiest way to do this may well be to create a tree control that is never shown on a form, and populate it. Otherwise you need to create a node class which contains a list of children, the list would contain instances of the same class, so that you can have children down to any level you like. You can use recursion to iterate over the entire tree.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: he easiest way to do this may well be to create a tree control that is never shown on a form, and populate it.
IMO that's bad practice, assuming we're in WinForms world here. Using hidden controls as a data structure is a bad practice to carry over from web dev to windows dev (no offense to you, Christian). There is a lot of overhead associated with a control (at least one window handle has to be created, all types of messages get sent to it, etc.) If you don't need a control, don't use one, it's really expensive.
:josh:
My WPF Blog[^]
|
|
|
|
|
Josh Smith wrote: (no offense to you, Christian).
None taken. I'm not always right It just struck me as a quick and dirty solution, I've not actually done it myself.
Josh Smith wrote: If you don't need a control, don't use one, it's really expensive.
I would not regard the overhead to be that much, certainly compared to the overhead of writing a tree structure, assuming one can't be found to use. But, like I said, I'm not claiming to always be right :P
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: I would not regard the overhead to be that much, certainly compared to the overhead of writing a tree structure, assuming one can't be found to use. But, like I said, I'm not claiming to always be right
It's common to underestimate the overhead of a windows control. Those suckers are heavy and eat up processing time (they are windows, after all). I used to be a windows control developer, so I spent a lot of time on these types of issues. So in this rare instance, I am claiming to be right.
:josh:
My WPF Blog[^]
|
|
|
|
|