|
Hi Guys
Need Help. I am using a dynamic created Textbox in code behind
However when i wanna retrieve the value from the Textbox which i have created, I always seem to hit an error and stuck at the part of retrieving value
Any sample or advise will be a blessing to me
Thanks A Millions
KaKaShi HaTaKe
|
|
|
|
|
You add the textbox using Controls.Add() . When creating the textbox from codebehind, you can assign it an ID say, tbDynamicId.
TextBox tb = new TextBox();
tb.ID = "tbDynamicId";
this.Controls.Add(tb);
Then you can get the textbox like:
TextBox tbDynamic = (TextBox)FindControl("tbDynamicId");
And then retrive the value normally,
String value = tbDynamic.Text;
|
|
|
|
|
string text = ((TextBox)this.Controls["ControlName"]).Text;
|
|
|
|
|
suppose i have form where toolstrip is there and that toolstrip contain many toolstrip button and other control. how can i find is there any toolstrip button exist or not on the form just by name. can i write any function like findcontrol where i pass the control name means toolstrip button name as string to that function and that function will iterate in all the controls on the form and check any toolstrip button exist having that name which i pass to that function. please help me with sample code.
i have written a code snippet which is not able to find out the toolstrip button. my code as follows
<br />
public static System.Windows.Forms.Control FindControl(string id, System.Windows.Forms.Form.ControlCollection col)<br />
{<br />
System.Windows.Forms.Control child = null;<br />
child = FindControlRecursive(c, id);<br />
if (child != null)<br />
return child;<br />
<br />
return null;<br />
}<br />
<br />
private static System.Windows.Forms.Control FindControlRecursive(System.Windows.Forms.Control root, string id)<br />
{<br />
if (root.Name != null && root.Name == id)<br />
return root;<br />
<br />
foreach (System.Windows.Forms.Control c in root.Controls)<br />
{<br />
System.Windows.Forms.Control rc = FindControlRecursive(c, id);<br />
if (rc != null)<br />
return rc;<br />
}<br />
return null;<br />
}<br />
plzzzz help
tbhattacharjee
|
|
|
|
|
A ToolStripButton [^] inherits from Component , not Control .
Good luck
--edit
The same answer has been given here[^]. I think the answer will stay the same, no matter how often you're going to post your question.
It's not going to work using the "FindControl" method. How about searching the items [^] collection of the ToolStrip ?
I are Troll
modified on Thursday, November 4, 2010 4:47 AM
|
|
|
|
|
As Eddy has told you, ToolStripButton is not a Control, so it is not added to any Controls collection.
If you want to find a ToolStripButton by name among several ToolStrip controls (ToolStrip does inherit from Control), you should first find the ToolStrip objects, using something similar to what you have done, and then use the string indexer of the Items property of these ToolStrip controls. I mean, if "ts" is a ToolStrip, and you want to see if a ToolStripButton named "tsbtn" is in that ToolStrip, you just have to try this:
ToolStripItem itm = ts.Items["tsbtn"];
If itm is null, the ToolStrip does not contain that item.
|
|
|
|
|
I want to add a custom toolbar to VS. This toolbar would have a combo on it and some buttons. Can someone point me in the right direction on how to do this?
Thanks
Everything makes sense in someone's mind
|
|
|
|
|
Take a look at the links in the answers on this thread[^].
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.”
|
|
|
|
|
Has anyone had problems with their final build not functioning the same as when in debug? I have a procedure that finds the selected item in a listbox and updates its associated data in the database. Basically, the listbox gets disabled during the update and re-enable when complete. Upon re-enabling, I set the selected item to the item that was just updated. This works fine in debug, but when I build the project and run the executable, the recently update item does not get selected, the first item in the list always gets selected. I know you can't diagnose my exact problem without looking at the code, but I thought it strange that the final build is not working as I expected after testing. I was wondering if anyone had some ideas of what to look for?
|
|
|
|
|
Are you updating your database on a background thread? If so, are you using Invoke to reenable the ListBox and select the item when the database update finishes?
|
|
|
|
|
No, I'm not running a background thread. I have an "edit" button that allows the user to edit the info in a series of textboxes that are linked to the values in the listbox. When the "edit" button is pressed, the listbox is disable to prevent the user from changing the selection. When the user is done, a "save" button is pressed, a SQL Update statement is run and the listbox is enabled. I stored the original selected item index, so I can return the selection to the same value.
|
|
|
|
|
Then I need to see the code. Otherwise I can't figure out what is going on.
|
|
|
|
|
kruegs35 wrote: I was wondering if anyone had some ideas of what to look for?
#IF DEBUG
Another thing to check would be the projects' properties; you might be using different path's, and thus, be including different things in the debug/compile versions.
I are Troll
|
|
|
|
|
I define new bitmap in my code
Bitmap image = new Bitmap( width, height, PixelFormat.Format8bppIndexed);
==> that mean that this bitmap is gray scale color.
Now, i want to define what color will be at place (i, j) so i usually use ( on 24 color bit ) the method 'SetPixel( i, j, Color.FromRGB( ... ) )'
But in this case that the bitmap is on gray scale i cant do it because i have only one value of the color ... and the application crash all the time when i try to
call Color.FromRGB(theOneColorIhave)
Someone know other way to do set the pixel values - some way that can be use with 8 bit format ?
Thanks
modified on Wednesday, November 3, 2010 10:36 AM
|
|
|
|
|
Try this function to get a color supported by your currently selected palette.
Greetings
Covean
|
|
|
|
|
You cannot use SetPixel if your bitmap pixel format is indexed, so you will have to use the BitmapData object returned by LockBits[^] method.
Edit
Ok, this is a little tricky, so I will give a little sample on how to do this before you have to ask again:
unsafe Bitmap ToGrayScale(Bitmap bmp)
{
Bitmap grayBmp = new Bitmap(bmp.Width, bmp.Height, PixelFormat.Format8bppIndexed);
ColorPalette pal = grayBmp.Palette;
for (int i = 0; i < 256; i++)
pal.Entries[i] = Color.FromArgb(i, i, i);
grayBmp.Palette = pal;
BitmapData bd = grayBmp.LockBits(
new Rectangle(0, 0, bmp.Width, bmp.Height),
ImageLockMode.ReadWrite,
PixelFormat.Format8bppIndexed);
byte* ptr = (byte*)bd.Scan0.ToPointer();
for (int i = 0; i < bmp.Width; i++)
{
for (int j = 0; j < bmp.Height; j++)
{
Color c = bmp.GetPixel(i, j);
ptr[j * bd.Stride + i] = (byte)((c.R + c.G + c.B) / 3);
}
}
grayBmp.UnlockBits(bd);
return grayBmp;
}
Sure I should have locked bits also for bmp, becouse GetPixel performance is really bad but, hey, I feel a little lazy today...
modified on Wednesday, November 3, 2010 12:01 PM
|
|
|
|
|
hello !
i making a remote support app and i trying to get the screen image when the computer is in lock mode or in log off mode and i can't.. i only get a black screen !!! can somebody help me ?
thx
|
|
|
|
|
Think about what state the system will be in if it is locked or if no user is logged on.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
You're getting a black screen because the image you're capturing is on a Desktop that is no longer visible. When the workstation is locked, the user see a different Desktop. Whatever you're using to capture the screen isn't written to handle multiple Desktops.
|
|
|
|
|
public static System.Windows.Forms.Control FindControl(string id, System.Windows.Forms.Form.ControlCollection col)
{
System.Windows.Forms.Control child = null;
foreach (System.Windows.Forms.Control c in col)
{
if (c.GetType().Name.ToUpper() == "TOOLSTRIP")
{
foreach (System.Windows.Forms.ToolStripItem item in ((System.Windows.Forms.ToolStrip)c).Items)
{
switch (item.GetType().Name)
{
case "ToolStripButton":
child = ((Control)((ToolStripButton)item));
break;
case "ToolStripComboBox":
break;
case "ToolStripLabel":
break;
case "ToolStripMenuItem":
break;
case "ToolStripProgressBar":
break;
case "ToolStripStatusLabel":
break;
case "ToolStripTextBox":
break;
}
}
}
else
{
child = FindControlRecursive(c, id);
}
if (child != null)
return child;
}
return null;
}
tbhattacharjee
|
|
|
|
|
Format your code using the pre tags, i.e. use the "code block" menu item.
Ask a question, the subject is not the question
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Tridip,
Some user interface elements are not controls, e.g. TreeNode, ToolTip and all of the classes derived from ToolStripItem. If you look at the base types for Button and ToolStripButton in the object browser you'll see
Button -> ButtonBase -> Control -> Component
ToolStripButton -> ToolStripItem -> Component
The consequence of this inheritance hierarchy is that a form's control collection does not contain the ToolStripItems and a ToolStripItem cannot be cast to a Control.
Alan.
|
|
|
|
|
hi!
in windows application, i am using datagridview in a form to display the records from the database.
my query is that, when i select the checkbox and click edit button of any record from the datagridview the related value of the selected checkbox appear on the textbox of second form.
please guide me on this.
thanx with regards
|
|
|
|
|
I might misinterpret your question, but if you want to know how to pass a value from Form1 to Form2 (that value being the selected value of a cell in datagrid), just read the value and send it as a parameter to the constructor of Form2 and set the Text property of the textbox (of Form2) to the parameter value.
|
|
|
|
|
Hi guys,
I have a huge problem and I have no idea how to fix it. I have two different web services - one we'll call LibrarySearch and one we'll call LibrarySorter. These are two different projects. Both have a class called Book and it's the same exact class.
But when I call each of them they return as LibrarySearch.Book and LibrarySorter.Book ... and I have no way of converting these to some generic item which I can use (without having to create two objects, one for each result depending on whether the user did a search or a sort).
Please help. I even tried to serialize to a stream, and de-serialize back and it still didn't work.
Thank you for your time.
In life truth does not matter. What really matters is what others believe to be the truth. (The Up and Comer - Book)
|
|
|
|