below I have some code to get the index from the selected row in a listView. But this only works if the user clicks on the first column. But if I have four columns, how would I do to let the user click anywhere on a row of the listView?
private void lvRegAnimals_SelectedIndexChanged(object sender, EventArgs e)
{
int index = lvRegAnimals.FocusedItem.Index;
// Code here to pass the index to method....
}
You have to set the ListView.FullRowSelect to true.
You could use ListView.SelectedItems property to do the work here,
Something like this
private void ListView1_SelectedIndexChanged_UsingItems(
object sender, System.EventArgs e)
{
ListView.SelectedListViewItemCollection breakfast =
this.ListView1.SelectedItems;
double price = 0.0;
foreach ( ListViewItem item in breakfast )
{
price += Double.Parse(item.SubItems[1].Text);
}
// Output the price to TextBox1.
TextBox1.Text = price.ToString();
}
For more info Go here
Related
I want to get the first element of telerik multi combo box which is a column of a telerik grid view
when user selects a row i want to get the first element of that row and pass it to my DB
i've done some thing but i geuss it's not enough
if (Ref_MultiColumnComboBox.MultiColumnComboBoxElement.SelectedIndex >= 0)
{
var tr = Ref_MultiColumnComboBox.MultiColumnComboBoxElement
.EditorControl.Rows[Ref_MultiColumnComboBox.MultiColumnComboBoxElement.SelectedIndex]
.Cells["Id"].Value.ToString();
MessageBox.Show("m= {0}" + " // " + tr);
}
else
{
MessageBox.Show("", "Error");
}
the problem is that when user selects some row or doesn't selectedindex is allways -1
Here is one way to do it for RadMultiColumnComboBox control:
void radMultiColumnComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewDataRowInfo selectedRow = (GridViewDataRowInfo)radMultiColumnComboBox1.SelectedItem;
Console.WriteLine(selectedRow.Cells["Id"].Value.ToString());
}
The SelectedItem provides a reference to the selected row in the inner grid, from where you can access its cells and values.
If GridViewMultiComboBoxColumn is used, then you can use either the ValueChanged event, or the CellValueChangned events to get the row of the currently selected item:
void radGridView1_CellValueChanged(object sender, GridViewCellEventArgs e)
{
RadMultiColumnComboBoxElement mccbEditor = (RadMultiColumnComboBoxElement)e.ActiveEditor;
GridViewDataRowInfo selectedRow = (GridViewDataRowInfo)mccbEditor.SelectedItem;
Console.WriteLine(selectedRow.Cells["Id"].Value.ToString());
}
void radGridView1_ValueChanged(object sender, EventArgs e)
{
RadMultiColumnComboBoxElement mccbEditor = (RadMultiColumnComboBoxElement)radGridView1.ActiveEditor;
GridViewDataRowInfo selectedRow = (GridViewDataRowInfo)mccbEditor.SelectedItem;
Console.WriteLine(selectedRow.Cells["Id"].Value.ToString());
}
I have a data grid view with QUANTITY, UNIT PRICE and VALUE columns. What I want to do is when changing the QUANTITY I need to change the VALUE .
VALUE = QUANTITY * UNIT PRICE
I wrote code for gridview 'CellValueChanged' event. But then VALUE will change when leaving the cell only. I need to change VALUE when typing the QUANTITY.
My code like this.Any idea please.
private void dgvSale_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (dgvSale.Columns[e.ColumnIndex].Name == "Qty")
{
double qty = Convert.ToDouble(dgvSale["Qty", dgvSale.CurrentRow.Index].Value);
double rate = Convert.ToDouble(dgvSale["Rate", dgvSale.CurrentRow.Index].Value);
double totVal = qty * rate;
dgvSale["Value", dgvSale.CurrentRow.Index].Value = totVal.ToString("#,###.00");
}
}
I don't know if I understood you right. You're trying to update the value on the fly, while typing? If so then you probably should use also DataGridView.CurrentCellDirtyStateChanged event to commit cell value changes. Below is the example based on MSDN:
private void dgvSale_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
if (dgvSale.IsCurrentCellDirty)
{
dgvSale.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
}
Is that what you need?
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex.Equals("column Index of Quantity"))
{
double total = Convert.ToDouble(dataGridView1["Subtotal column name", e.RowIndex].Value) * Convert.ToDouble(dataGridView1["Quantity column name", e.RowIndex].Value);
dataGridView1["Total Column name", e.RowIndex].Value = total.ToString();
}
}
enter link description here
I am working on a telerik report. In my report there are three textboxes (textBox14, textBox15,textBox16).
In textBox14 and 15, showing a sum of values from data source based on sum group criteria. I want to show the sum of the textBox14 and 15 values in 16. How can I get the values of the textBox 14 and 15 in textBox16's ItemDataBinding or ItemDataBound event.
private void textBox16_ItemDataBound(object sender, EventArgs e)
{
string amt= textBox14.Value; // It getting only the mapped field name. ie Fields.amt, but I want the display text of the textBox14. There is no .Text property for textBox14.
string tax= textBox15.Value; // It getting only the mapped field name. ie Fields.tax, but I want the display text of the textBox14. There is no .Text property for textBox15.
}
I want to set the textBox16 value as
textBox16.Value = Convert.ToString(ConvetToInt32(amt) + ConvetToInt32(tax));
How can I get the values ?.
private void textBox16_ItemDataBound(object sender, EventArgs e)
{
string amt = textBox14.Text;
string tax = textBox15.Text;
}
and then call:
textBox16.Text = Convert.ToString(Convert.ToInt32(amt) + Convert.ToInt32(tax));
why don't you try the detail_ItemDataBound event
private void detail_ItemDataBound(object sender, EventArgs e)
{
Telerik.Reporting.Processing.DetailSection section = (sender as Telerik.Reporting.Processing.DetailSection);
Telerik.Reporting.Processing.TextBox = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper.GetChildByName(section, "textBox14");
Telerik.Reporting.Processing.TextBox = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper.GetChildByName(section, "textBox15");
Telerik.Reporting.Processing.TextBox txtTotal = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper.GetChildByName(section, "textBox16");
txtTotal.Value = (Convert.ToInt32(txtAmt.Value) + Convert.ToInt32(txtTax.Value)).ToString();
}
I have a WPF line series chart,
when a datapoint is selected the selection changed event is fired.
What i want to know is, is there a way to give the datapoints ID values so that i can get them from inside the selection event
something like:
private void LineSeries_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
{
int id = ((something)sender).id;
}
The SelectionChangedEventArgs should provide you the information you need. The property AddedItems contains the DataPoints that is/are selected and the property RemovedItems contains the DataPoints that where previously selected.
You need to cast the items in the collection to the Type (DataPoint or LineDataPoint for LineSeries)you need.
private void LineSeries_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
{
DataPoint selectedPoint = null;
if (e.AddedItems.Count > 0){
selectedPoint = e.AddedItems[0];
}
}
I try to use combobox in winforms project.
Here is my code:
private void ShowContoursForm_Load(object sender, EventArgs e)
{
cbxSelectShape.DisplayMember = dataSetObject.ObjectShapes.ShapeNameColumn.ColumnName;
cbxSelectShape.ValueMember = dataSetObject.ObjectShapes.ShapeIDColumn.ColumnName;
cbxSelectShape.DataSource = dataSetObject.ObjectShapes;
}
private void cbxSelectShape_SelectedValueChanged(object sender, EventArgs e)
{
var id= (int)cbxSelectShape.SelectValue;
}
When I choose item from ComboBox SelectedValueChanged is fired,and id variable gets null.
I need to get value of selected item but I always get null in id variable.
Any idea why do I get wrong result and how to fix this code?
You can get the index of ComboBox this way:
private void cbxSelectShape_SelectedValueChanged(object sender, EventArgs e)
{
var id= ((ComboBox)sender).SelectedIndex;
}
You should use SelectedValue property of combobox to get value, associated with ValueMember (ShapeID in your case):
var id = ((ComboBox)sender).SelectedValue;
SelectedIndex returns index of item selected in combobox. Also if this handler used for one combobox, you don't need to cast sender - simply use your combobox variable:
var id = cbxSelectShape.SelectedValue;