I am trying to set a value for a radcombobox based on the textchanged event(updatestatus) of one textbox.
Its not changing the value.
<telerik:RadComboBox ID="ddlStatus" runat="server" Enabled="false"/>
protected void updatestatus(object sender, System.EventArgs e)
{
if (txtname.Text != String.Empty)
{
if (ddlStatus.Text.Trim() == "Waiting")
{
ddlStatus.Text = "complete";
}
}
}
Can Some one suggest me if I am missing something.?
You can use FindItemByText to set value of Talerik dropdown:
RadComboBoxItem item = ddlStatus.FindItemByText("complete");
item.Selected = true;
Complete implementation in your case will be something like this:
protected void updatestatus(object sender, System.EventArgs e)
{
if (txtname.Text != String.Empty)
{
if (ddlStatus.Text.Trim() == "Waiting")
{
RadComboBoxItem item = ddlStatus.FindItemByText("complete");
item.Selected = true;
}
}
}
Related
I have a problem with checkbox. I'm trying to explain.
My Datagrid can have multiple row, so multiple checkbox.
When one or many checkbox is true, so a button IsEnable=true. But if no checkbox is true, so the button is disable.
Maybe an issue with a count of checkbox IsChecked ? Or maybe the click processus is not appropriate?
Here is my code :
private void Chk_UID_IsSelected_Click(object sender, RoutedEventArgs e)
{
var Chkbox = sender as CheckBox;
if (Chkbox.IsChecked == true)
{
UID_Disconnect.IsEnabled = true;
}
else
{
UID_Disconnect.IsEnabled = false;
}
}
But my code check only one checkbox in fact. If i click on 2 checkbox and uncheck one, my button have an incorrect state.
My design :
Another try with no result:
private void Chk_UID_IsSelected_Click(object sender, RoutedEventArgs e)
{
foreach (CheckBox c in dgConnected_Users.ItemsSource)
{
var Chkbox = sender as CheckBox;
UID_Disconnect.IsEnabled = Chkbox.IsChecked == true;
}
}
Here another try with no result:
private void Chk_UID_IsSelected_Click(object sender, RoutedEventArgs e)
{
int checkedBoxes = dgConnected_Users.Items
.OfType<CheckBox>().Count(c => (bool)c.IsChecked == true);
if (checkedBoxes > 0)
{
// You shall pass!
UID_Disconnect.IsEnabled = true;
}
else
{
// None shall pass
UID_Disconnect.IsEnabled = false;
}
}
OK I have progress in my code, here the new one :
private void Chk_UID_IsSelected_Click(object sender, RoutedEventArgs e)
{
foreach (DataRowView dr in dgConnected_Users.ItemsSource)
{
var Chkbox = sender as CheckBox;
if (Chkbox.IsChecked == true)
{
isAnyChecked++;
}
else
{
isAnyChecked--;
}
}
if (isAnyChecked > 0)
{
UID_Disconnect.IsEnabled = true;
}
else
{
UID_Disconnect.IsEnabled = false;
}
}
That do the staff, but i know that if I check just one checkbox, 'isAnyChecked' = 2, or it must be equal 1.
i have this following code :
<asp:DropDownList ID="dd_SubCategory" Width="160px" runat="server" DataTextField="CATEGORY_NAME" DataValueField="CATEGORY_ID"></asp:DropDownList>
<br />
<asp:Panel ID="pnl_SubCatg" runat="server"></asp:Panel>
<asp:ImageButton ID="Ib_AddSubCategory" runat="server" OnClick="Ib_AddSubCategory_Click" ImageUrl="/images/add.gif" />
protected void Ib_AddSubCategory_Click(object sender, ImageClickEventArgs e)
{
string SelectedCategory="";
if (ctrl_list.Count == 0)
SelectedCategory = dd_SubCategory.SelectedValue;
else
SelectedCategory = Session["Selected_SubCatg"] != null && Session["Selected_SubCatg"].ToString()!=""?Session["Selected_SubCatg"].ToString():((DropDownList)ctrl_list[ctrl_list.Count - 1]).SelectedValue;
try
{
DataRow[] Rows = DataHelper.TicketCategories.Select("PARENT_CATEGORY_ID='" + SelectedCategory + "'");
if (Rows.Length > 0)
{
AddSubCategory(Rows);
}
foreach (Control item in ctrl_list)
pnl_SubCatg.Controls.Add(item);
}
catch (Exception ex)
{ }
}
List<Control> _ctrl_list = null;
List<Control> ctrl_list {
get
{
if (Session["SUB_CATG_LIST"] == null)
{
_ctrl_list = new List<Control>();
Session["SUB_CATG_LIST"] = _ctrl_list;
}
return Session["SUB_CATG_LIST"] as List<Control>;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["SUB_CATG_LIST"] = null;
Session["Selected_SubCatg"] = null;
}
if (ctrl_list.Count > 0)
{
foreach (Control item in ctrl_list)
pnl_SubCatg.Controls.Add(item);
}
}
private void AddSubCategory(DataRow [] Rows)
{
DropDownList dd_SubCategory1 = new DropDownList();
dd_SubCategory1.Width = Unit.Pixel(160);
dd_SubCategory1.DataTextField = "CATEGORY_NAME";
dd_SubCategory1.DataValueField = "CATEGORY_ID";
dd_SubCategory1.ID = Guid.NewGuid().ToString();
dd_SubCategory1.DataSource = Rows.CopyToDataTable();
dd_SubCategory1.DataBind();
dd_SubCategory1.SelectedIndexChanged += dd_SubCategory1_SelectedIndexChanged;
dd_SubCategory1.AutoPostBack = true;
ctrl_list.Add(dd_SubCategory1);
}
void dd_SubCategory1_SelectedIndexChanged(object sender, EventArgs e)
{
Session["Selected_SubCatg"] = ((DropDownList)sender).SelectedValue;
}
i am trying to add a dropdown list containing the subcategories of the last inserted dropdown list , my problem is dd_SubCategory1_SelectedIndexChanged is not firing and i can't get the and the selectedValue of the last dropdownlist is always the same
That is because its dynamically generated and it will lose its state after its rendered on your page.
To access the dropdown and its related events and properties, you will need to recreate it everytime your page is postback.
Hope its clear enough.
I would like to show a product balance in a TextBox when a product is selected from DataGridView.
When product is selected and the tab button is pressed then the product balance should be shown in the TextBox.
All the data is loaded from an Microsoft Access database. How can i achieve this.
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
e.Control.KeyPress -= new KeyPressEventHandler(dataGridView1_KeyPress);
if (dataGridView1.CurrentCell.ColumnIndex == 1) //Desired Column
{
//getSum() function gives sum of a db table column
textBox1.Text = getSum();
}
}
I would add a KeyDown and a KeyUp event Handler to the DataGridView Or your Form or whatever can has focus on the time ;).
When the Key, which is pressed down is Tab i would set a member variable to true or false.
Here a short example of what i mean.
public partial class Form1 : Form
{
bool isTabPressed = false;
public Form1()
{
InitializeComponent();
button1.KeyDown += button1_KeyDown;
button1.KeyUp += button1_KeyUp;
}
void button1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Tab)
{
isTabPressed = true;
}
}
void button1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Tab)
{
isTabPressed = false;
}
}
}
Everything else you can do in your method, that you are currently writing and just check if isTabPressed is true.
Hope this helps.
If not leave a comment ;)
EDIT:
So something like this ?
Currently what it does is: you choose something and when you press tab it writes it to the textbox:
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
editControlWasOpened = true;
}
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (dataGridView1 != null && dataGridView1.CurrentCell != null && dataGridView1.CurrentCell.Value != null && editControlWasOpened )
{
textBox1.Text = dataGridView1.CurrentCell.Value.ToString();
}
valueischanged = false;
}
From what i understand, based on the value you select in you ComboBox, getSum() wiill go and retrieve the total value from the database. If that's the case then add a SelectedIndexChanged event but casting the DataGridViewComboBoxCell into a ComboBox like the code below.
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
var combobox = e.Control as ComboBox;
if (combobox != null)
{
combobox.SelectedIndexChanged -= ComboBox_SelectedIndexChanged;
combobox.SelectedIndexChanged += ComboBox_SelectedIndexChanged;
}
}
private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
var combobox = sender as ComboBox;
if (combobox != null)
{
var item = combobox.SelectedItem.ToString();
if (!string.IsNullOrEmtpy(item))
{
textBox1.Text = getSum();
// Adjust the line above as per your requirement.
// I don't fully understand what getSum() does as you haven't posted it
}
}
}
After a long time this was done .......and i am posting this for other user too!
My Question was
"**I would like to show a product balance in a TextBox when a product is selected from DataGridView. When product is selected and the tab button is pressed then the product balance should be shown in the TextBox. All the data is loaded from an Microsoft Access database. How can i achieve this."
I think the subject is "how to show textbox value when datagridview combobox value is selected"
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
if (dataGridView1.CurrentCell.ColumnIndex == 0) //Desired Column
{
myCon.Open();
OleDbCommand cmd1 = new OleDbCommand("SELECT sum_stock_purchase_quantity, sum_stock_purchase_quantity_thaan from productPurchaseQuery where stock_product_id=" + this.dataGridView1.CurrentCell.Value.ToString() + "");
cmd1.Connection = myCon;
OleDbDataReader reader = null;
reader = cmd1.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
textBox9.Text = Convert.ToString(reader["sum_stock_purchase_quantity"]);
textBox2.Text = Convert.ToString(reader["sum_stock_purchase_quantity_thaan"]);
}
}
else
{
textBox9.Text = "0.0";
textBox2.Text = "0.0";
}
myCon.Close();
Guys i did this. But this may be good or bad. But my objective is achieved.
I am using an XtraGridView control in my winform. Now I added a RepositoryItemHyperLinkEdit to it. But I want to show/hide each link according to the row data.
How can I achieve this?
Thanks for any help..
I tried the next code but it did not work, the cell did not be empty.
("Show link" part is ok, but String.Empty does not work)
private void xgvGrid_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
{
if (e.Column == gcControlField)
{
if (xgvGrid.GetFocusedRowCellValue("ControlField") != null)
{
if (xgvGrid.GetFocusedRowCellValue("ControlField").ToString() == "LINK")
e.DisplayText = "Show link";
else
e.DisplayText = string.Empty;
}
}
}
You can add your checking in the event GridView.CustomColumnDisplayText.
e.g. Each row is bind to a Person instance
private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
{
// gcLink is your column using repositoryitemhyperlinkedit
if (e.Column == gcLink)
{
var person = gridView1.GetRow(e.RowHandle) as Person;
if (person != null)
{
// Logic to show/hide the link based on other field
if (person.FirstName == "John")
e.DisplayText = string.Empty;
else
e.DisplayText = person.Link;
}
}
}
I have a Dropdownlist (DDL1) when I select any item from this dropdownlist(DDL1), results in creation of another dropdownlist(DDL2), This contains some of the items.When I select other Item from DDL1 , Items will change in DDL2, this happens for the each different item selected in DDL1.
when I select a item from DDL2, label content must be shown, intially I'm making Label invisibe and in the code I changed the visibility to true and added content to it. But the label content is not shown when I select a item from DDL2.
Here is my Code
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedValue == "Abe Books")
{
DropDownSeller.Visible = true;
lnkUsdBooks.Visible = true;
lnkUsdBooks.Text = "usedbooks#abe.com";
lnkUsdBooks.NavigateUrl = "mailto:usedbook#abe.com";
DropDownSeller.Visible = true;
DropDownSeller.Items.Remove("Chacha Choudary");
DropDownSeller.Items.Remove("SpiderMan");
DropDownSeller.Items.Remove("Amar chitra Katha");
DropDownSeller.Items.Remove("Chandamama");
DropDownSeller.Items.Remove("Mahabharata");
DropDownSeller.Items.Add("Amar chitra Katha");
DropDownSeller.Items.Add("Chandamama");
DropDownSeller.Items.Add("Mahabharata");
DropDownSeller.DataBind();
if (DropDownSeller.SelectedValue == "Amar chitra Katha")
{
lblPrice.Visible = true;
lblPrice.Text = "$69.99";
}
else if (DropDownSeller.SelectedValue == "Chandamama")
{
lblPrice.Visible = true;
lblPrice.Text = "$59.99";
}
else if (DropDownSeller.SelectedValue == "Mahabharata")
{
lblPrice.Visible = true;
lblPrice.Text = "$49.99";
}
else
{
lblPrice.Visible = false;
}
}
Any ideas on this are appreciated
Thanks,
Remove if (!Page.IsPostBack) from the DropDownList1_SelectedIndexChanged because when the page postbacks this condition will be false. Because your page is posting back to the server that's why it is not visible and not showing.
In short your DropDownList1_SelectedIndexChanged should be like..
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedValue == "Abe Books")
{
DropDownSeller.Visible = true;
lnkUsdBooks.Visible = true;
lnkUsdBooks.Text = "usedbooks#abe.com";
lnkUsdBooks.NavigateUrl = "mailto:usedbook#abe.com";
DropDownSeller.Visible = true;
DropDownSeller.Items.Clear(); // it will clear all the items, instead you are removing one by one
DropDownSeller.Items.Add("Amar chitra Katha");
DropDownSeller.Items.Add("Chandamama");
DropDownSeller.Items.Add("Mahabharata");
DropDownSeller.DataBind();
}
protected void DropDownSeller_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownSeller.SelectedValue == "Amar chitra Katha")
{
lblPrice.Visible = true;
lblPrice.Text = "$69.99";
}
else if (DropDownSeller.SelectedValue == "Chandamama")
{
lblPrice.Visible = true;
lblPrice.Text = "$59.99";
}
else if (DropDownSeller.SelectedValue == "Mahabharata")
{
lblPrice.Visible = true;
lblPrice.Text = "$49.99";
}
else
{
lblPrice.Visible = false;
}
}