This must be simple, but I have trouble to get this solved ...
I have a mouse click event proc of which the sender type is a RadTextBoxItem. I need to know the textbox, so type TextBox or RadTextBox. How can this be done?
public class MyCustomVisualItem : SimpleListViewVisualItem { private LightVisualElement _contentElementName; private LightVisualElement _contentElementState; private StackLayoutPanel _stackLayoutH; private StackLayoutPanel _stackLayoutV; private ImagePrimitive _image1; protected override void CreateChildElements() { base.CreateChildElements(); _stackLayoutH = new StackLayoutPanel { Orientation = Orientation.Horizontal, EqualChildrenWidth = false }; _stackLayoutV = new StackLayoutPanel { Orientation = Orientation.Vertical, EqualChildrenWidth = true, Margin = new Padding(10,0,0,0) }; _image1 = new ImagePrimitive { Image = (Image)Resource1.ResourceManager.GetObject("Anonymous"), Alignment = ContentAlignment.MiddleLeft }; _stackLayoutH.Children.Add(_image1); _contentElementName = new LightVisualElement { StretchHorizontally = true, Alignment = ContentAlignment.MiddleLeft, ImageAlignment = ContentAlignment.MiddleLeft, TextAlignment = ContentAlignment.MiddleLeft, Image = (Image)Resource1.ResourceManager.GetObject("Untitled_1s"), TextImageRelation = TextImageRelation.ImageBeforeText }; _stackLayoutV.Children.Add(_contentElementName); _contentElementState = new LightVisualElement { StretchHorizontally = true, Alignment = ContentAlignment.MiddleLeft, TextAlignment = ContentAlignment.MiddleLeft, ForeColor = Color.Gray, }; _stackLayoutV.Children.Add(_contentElementState); _stackLayoutH.Children.Add(_stackLayoutV); Children.Add(_stackLayoutH); } protected override void SynchronizeProperties() { base.SynchronizeProperties(); Text = ""; _contentElementName.Text = Convert.ToString(Data["Name"]); _contentElementState.Text = "Life is Good"; } protected override Type ThemeEffectiveType { get { return typeof(SimpleListViewVisualItem); } } }
Action radListView1_SelectedItemChanged in ListView doesn't work when i click on LightVisualElement element in my custom ListView item.public RadForm1() { InitializeComponent(); this.radListView1.Columns.Add("Name"); this.radListView1.Items.Add(new ListViewDataItem("text")); this.radListView1.Items[0]["Name"] = "User"; } private void radListView1_VisualItemCreating(object sender, Telerik.WinControls.UI.ListViewVisualItemCreatingEventArgs e) { e.VisualItem = new MyCustomVisualItem(); } private void radListView1_SelectedItemChanged(object sender, EventArgs e) { int s = 2; }
private
void
radButtonElementEnglish_Click(
object
sender, EventArgs e)
{
ChangeLanguage(
this
,
"English"
)
}
public
void
ChangeLanguage(Form frm, String Language =
"English"
)
{
RadTextBox RadTextBoxTip =
null
;
RadDropDownListCustom radDropDownListCustomTip =
null
;
RadLabel radLabelTip =
null
;
RadButtonElement radButtonElementTip =
null
;
RadGridView radGridViewTip =
null
;
SqlCommand commandGetData =
null
;
try
{
commandGetData = SQLQuery();
commandGetData.CommandText =
"SELECT Element_Name, Element_Typ, Element_Text_EN, ToolTip_Text_EN, Element_Text_DE, ToolTip_Text_DE, From Language WHERE Windowr_Name = @Window_Name"
;
commandGetData.Parameters.AddWithValue(
"@Window_Name"
, frm.Name.ToString());
commandGetData.Connection.Open();
SqlDataReader DataReader = commandGetData.ExecuteReader();
if
(DataReader.HasRows)
{
while
(DataReader.Read())
{
switch
(DataReader[
"Element_Typ"
].ToString())
{
case
(
"radTextBox"
):
RadTextBoxTip = (RadTextBox)frm.Controls.Find(DataReader[
"Element_Name"
].ToString(),
true
)[0];
if
(Language ==
"English"
)
{
RadTextBoxTip.Text = DataReader[
"Element_Text_EN"
].ToString();
RadTextBoxTip.TextBoxElement.TextBoxItem.ToolTipText = DataReader[
"ToolTip_Text_EN"
].ToString();
}
if
(Language ==
"German"
)
{
RadTextBoxTip.Text = DataReader[
"Element_Text_DE"
].ToString();
RadTextBoxTip.TextBoxElement.TextBoxItem.ToolTipText = DataReader[
"ToolTip_Text_DE"
].ToString();
}
break
;
case
(
"radLabel"
):
radLabelTip = (RadLabel)frm.Controls.Find(DataReader[
"Element_Name"
].ToString(),
true
)[0];
// same as radtextbox
//radLabelTip.Text
//radLabelTip.LabelElement.ToolTipText
break
;
case
(
"radRibbonbonbar"
):
//..
RadRibbonBar RadRibbonbarTip = (RadRibbonBar)frm.Controls.Find(DataReader[
"Element_Name"
].ToString(),
true
)[0];
//RadRibbonbarTip.Text = ..
//No Tooltip here
break
;
case
(
"ribbonTab"
):
//..
break
;
case
(
"radButtonElement"
):
var c = GetAll(frm,
typeof
(RadRibbonBar));
MessageBox.Show(
"Total Controls: "
+ c.Count());
break
;
//more case:
default
:
break
;
}
}
DataReader.NextResult();
}
commandGetData.Connection.Close();
}
catch
(System.Data.SqlClient.SqlException ex)
{
// showEvents(ex);
}
finally
{
if
(commandGetData !=
null
) { commandGetData.Dispose(); }
}
}
}
public
IEnumerable<Control> GetAll(Control control, Type type)
{
var controls = control.Controls.Cast<Control>();
return
controls.SelectMany(ctrl => GetAll(ctrl, type))
.Concat(controls)
.Where(c => c.GetType() == type);
}
We are using Winforms Q3 2011. In our application, many of our dropdown lists are populated from lookup tables, so we have a generic method that maps to a lookup type, and we set the datasource to that:
Dim MyList as List(of AC.Lookup) = '... EF code
ddl.DataSource = MyList
Many of the lists are not required fields, so the proper default is to have nothing selected. When this is the case, however, the dropdown lists will have "AC.Lookup" displayed (where AC is the namespace for this EDMX file). After investigating, what appears to be happening is that the datasource doesn't quite know what to do with an empty list, so somehow it is calling the ToString.
This is confusing to the users. :-) I first looked for a "default text" or some other such property on the dropdown list, and when I couldn't find that, I tried to do various hacks, mainly around setting the text to nothing after some event (DataBinding, TextChanged, whatever). That method failed, too. What I ended up doing was creating a partial class tied to the Lookup class (the original Lookup class is generated from the designer, so I didn't want to change it), overriding ToString to return String.Empty. That worked and solved our problem, but it still seems very hackish.
Do you have a better, more elegant solution?
Thanks!
foreach
(GridViewDataColumn dataColumn
in
radGridBatches.Columns)
{
dataColumn.TextAlignment = ContentAlignment.BottomRight;
dataColumn.FormatString =
"{0:F2}"
;
}