How to update a textbox in asp.net gridview dynamically - c#

I have two columns in gridview.
One is textbox and the other is also a textbox.
If one textbox text changed , i need to perform some calculation and again need to
fill automatically the second textbox.
(e.g) Ifi enter 10 in 1st textbox, i need to perform some calculation and again the result
of that manipulation needs to shown in the textbox automatically once the text is entered
in the first textbox.
I am not getting a way to achieve this..
please help me.

You need to handle the Leave Event of the first TextBox TextBox1.
Try This:
textBox1.Leave += new System.EventHandler(textBox1_Leave);
private void textBox1_Leave(object sender, EventArgs e)
{
//Do calculations on TextBox1 value to display the result on TextBox2
}

Related

Strange Bahavior when using RowEnter Event in DataGridView

I have a datagridview, a list with the same content as the datagridview and a textbox, when I change the row, the content of the textbox changes according to the row that I have selected (they are not linked through databind, but I change the content manually). Up to here everything works fine.
Now, I need that, if I modify the content of the textbox, and I change the row selected in the datagridview, before changing the row selected, check if the content of the textbox has been modified, and if it has, ask if I want to save the changes in the list.
For this task, I thought of using the RowEnter event of the datagridview, comparing the content of the textbox with the content of the list, but I ran into a difficulty, when I put a MessageBox inside the rowenter event, to ask if I want to save or not, no matter if I answered yes or no, the row of the datagridview does not change, and I want it to change the row right after asking, whether or not I saved the textbox change, or if there is another way to check if I change the content of the textbox with respect to the list, after changing the row in the datagridview
I leave part of the code that I am using.
private void dgvVisitas_RowEnter(object sender, DataGridViewCellEventArgs e)
{
if (numeroFilaVisitaActual == e.RowIndex)
{
if (txtNotasVisita.Text != listaVisitasPaciente[e.RowIndex].Notas)
{
MessageBox.Show("No es igual"); // If this Message is show, the row don't change
}
}
numeroFilaVisitaActual = e.RowIndex;
}

How to insert value from textbox and button to each row in certain column?

I have gridview with 4 columns. columns 1 to 2 bound to database and 3 to 4 is containing label. for input I have 2 textbox (textbox1 and texbox2)and 1 button (button1).
my question is:-
the gridview dataset is generated after I retrieve data from database (with another input). so can I insert value using textbox1 and textbox2 to each row in column 3 and column 4 after I click button1.
if can be insert, how can i generate it?
I've been trying many examples/ solutions but failed.
thank you.
I guess you just need to put some code where your button is with the textbox1 address.
private void button1_Click(object sender, EventArgs e) // your simple button function
{
textbox_output.Text = text_you_wish;
}
its kind of hard to understand what do you mean without posting a code or a picture of the code...

How to add text boxes dynamically when one text box is filled?

I have text box to fill the ph.numbers in that, here what i want is, whenever i'm entering the value in that text box i need to add another empty text box dynamically where i can add another value in that in the same way if they are entering any value into this new empty box another empty text box should add at the bottom of this. And after all there is a confirm link button. When clicking on it all these ph.numbers entering on the text boxes should get. How is it possible?
You add textboxes dynamically using jquery and on the button click/submit there values to the server. What you can do is on keyup event of a textbox you can add another below it.
Try this.
I'm basing this condition that your number format is of 11, Ex: 09123456789
So on the Textbox_Textchanged event of your textbox.
if(textbox.text.length >= 11)
{
Textbox text = new Textbox();
text.TextChanged += Textbox_Textchanged; // So it would also trigger the event
// Do positioning here
}
Im thinking you can better optimize this by having a better EventArgs but you get the idea right?

.Net C# windows forms, listbox control question

I have a pretty simple form with a listbox, a text box, and two buttons.
The list box items are populated from a sql database table. The user may chose to select one or multiple items from the listbox.
The text box is used to write more details about the items in the listbox. One button can then be clicked to update another database table with these details.
I want to make it where if any items are selected from the listbox, those contents are automatically copied into the text box field on the fly as they are selected.
Is this possible?
I've been able to make this happen on the button click event - just not on the fly as they are selected. I want it to occur before the additional details are being sent to the database
I've also tried using several different listbox events, but have been unable to obtain the results I am looking for.
Any suggestions?
try this out
you will have to handle the SelectedIndexChanged event on the listbox.
here is an example with example controls.
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
textBox1.Text = "";
foreach (string nextitem in listBox1.SelectedItems)
{
textBox1.Text += nextitem + " ";
}
}
im not too sure HOW you want the text to appear in the textbox so that would be up to you in the foreach loop.
yes, the SelectedIndexChanged event fires on every selection change, and you can concatenate together the items in the listbox. But if you are talking the description that's not visible too, you need to store the description in each listboxitem tag property, and in your code retrieve the description from there.

C#: Changing caret position in a DataGridView

In a TextBox, I could use textBox1.SelectionStart = 4. How can I do this in a DataGridView?
edit for clarification: suppose a specific cell is already selected and in editing mode. If I push the right arrow key, the caret moves to the right one position over whatever text is in that cell. I wish to create a button that does the same thing.
You should probably clarify a bit. Do you mean to change the selected row in a DataGridView or is there a textbox in your DataGridView that you want to move the caret for?
If you're looking to modify the selected row, try the SelectedIndex property.
private void RadGridView1_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangeEventArgs e)
{
RadGridView1.CurrentItem = RadGridView1.SelectedItem;
}
You need to get the TextBox via the DataGridView's EditingControlShowing event.
Store this is a member variable, and when you need to, access the textBox member and set the SelectionStart as you wrote above.
Something like;
dataGrid.EditingControlShowing += this.dataGrid_EditingControlShowing;
and
void dataGrid_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if(this.dataGrid.CurrentCell != null && e.Control is TextBox)
{
this.currentTextBox = (TextBox)e.Control;
}
}
Whenever the user would click your button, the cell in the DataGridView would lose focus, so it will remove the edit box, validate the value, and put the formatted value in the cell.
I wonder what your reasons are for having a button move the caret?

Categories

Resources