I've been stuck of this for a while and would love some insight.
When I add a new user or source and check the drawn checkbox, it causes the bool to be true when checked, as expected.
However it also checks all the other users connected to that source as true or false.
[before]
[after]
This only occurs when I load the XML file into my program that already had existing data, then add new Users or Sources via the UI.
this is a part of the LoadXML Method.
// Load the source list
sourceProps.SystemSources.Clear();
fCMUserSourceBindingSource.Clear();
fCMSourceBindingSource.Clear();
foreach (FusionSource src in fusionSystem.sourceList)
{
FCMSource fSource = new FCMSource(src);
sourceProps.SystemSources.Add(fSource);
fCMSourceBindingSource.Add(fSource);
fCMUserSourceBindingSource.Add(fSource);
}
txtSourceID.Text = sourceProps.GenerateNextSourceId();
// Load the user data from the fusionSystem object.
userProfile.SystemUserList.Clear();
//currently clears grid. might need to clear list instead
fCMUserBindingSource.Clear();
foreach (FusionUser usr in fusionSystem.userList)
{
FCMUser fUser = new FCMUser(usr);
userProfile.SystemUserList.Add(fUser);
fCMUserBindingSource.Add(fUser);
foreach (FusionSourcePermission srcPerm in usr.SourcePermissionList)
{
FCMSource fSource = new FCMSource(srcPerm);
fUser.fusionUserSources.Add(fSource);
}
}
AddColumnsUsersToSourceAllocation();
txtUserID.Text = userProfile.GenerateNextUserId();
// Load the zone group data from the fusionSystem object
zoneProps.systemZoneGroupList.Clear();
fCMZoneGroupBindingSource.Clear();
Any help would be appreciated.
Edit
The ListView is not binded and all the 'checking' is done programmatically when the user activates the click event.
private void lstSourceToUser_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
if (e.ColumnIndex > 1)
{
int usrIndex = userProfile.GetUserIndexByID(e.Header.Name);
int srcIndex = userProfile.GetUsersSourceIndex(e.Header.Name, e.Item.SubItems[0].Text);
Graphics g = e.Graphics;
CheckBoxRenderer.DrawCheckBox(g,new Point((e.Bounds.X + e.Bounds.Width/2 -10 ),(e.Bounds.Y)), userProfile.SystemUserList[usrIndex].fusionUserSources[srcIndex].UserSourceChkBox.MyCheckedState ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal);
}
else
// Draw the other subitems with default drawing.
e.DrawDefault = true;
}
Edit
This is the FCMSource constructor.
public FCMSource(string sourceId, string sourceName, string icnId, string lstIndx)
{
id = sourceId;
icon = icnId;
name = sourceName;
listIndex = lstIndx;
UserSourceCheckState = false;
UserSourceChkBox = new MyCheckBoxItem(false);
}
public FCMSource(FCMSource fSource, bool chk)
{
name = fSource.name;
icon = fSource.icon;
id = fSource.id;
listIndex = fSource.listIndex;
UserSourceCheckState = chk ? true : false;
UserSourceChkBox = new MyCheckBoxItem(chk);
}
And this is the FCMUser constructor which contains the different Sources.
public FCMUser(string userid, string nm, string icn, string pinNo, CheckBox pinEn, string lstIndx)
{
id = userid;
name = nm;
icon = icn;
pin = pinNo;
pinEnabled = pinEn.CheckState;
chkBoxPINEnable = new MyCheckBoxItem(false);
fusionUserSources = new List<FCMSource>();
ListIndex = lstIndx;
updateCheckbox();
}
everyone. I have a web service with all cars in company with data:
CarNumber and CarBrand.
I want, where I choose CarNumber from DropDownList, CarBrand autocomplete in textBox.
This is my Web controls declaration;
ddCarNumber = new DropDownList();
ddCarNumber.Items.Add("-- Choose Car Number --");
ddCarNumber.SelectedIndexChanged += new EventHandler(ddCarNumber_SelectedIndexChanged);
GetCars();
this.Controls.Add(ddCarNumber);
lblCarBrand.Text = "Car Brand";
txtCarBrand = new TextBox();
txtCarBrand.MaxLength = 255;
this.Controls.Add(txtCarBrand);
Whit this method i get CarNumbers from Web Service:
private void GetCars()
{
Service1SoapClient client = new Service1SoapClient();
UserDetails details = new UserDetails();
details.userName = "Weber";
details.password = "!Q2w#4r";
DataTable dt = client.GetCars(details);
foreach (DataRow row in dt.Rows)
{
ddCarNumber.Items.Add(row[0].ToString());
}
}
I want where i choose CarNumber from DropDown, TextBox autoComplete with CarBrand.
in Dropdown selectedIndex Change Event
ddCarNumber_SelectedIndexChanged
Write below code
this.Controls.findcontrol("txtCarBrand").Text = ddCarNumber.SelectedItem.Text/Value //Based on your Data DataTextField/DataValueField
Hope this helps.
This is : my ddCarNumber_SelectedIndexChanged Method, This is working, but problem is with Event, not refresh a page... When I push F5 is Okay...
void ddCarNumber_SelectedIndexChanged(object sender, EventArgs e)
{
Service1SoapClient client = new Service1SoapClient();
UserDetails details = new UserDetails();
details.userName = "Weber";
details.password = "!Q2w#4r";
DataTable dt = client.GetCars(details);
foreach (DataRow row in dt.Rows)
{
if (ddCarNumber.SelectedValue == Convert.ToString(row[0]))
{
txtCarBrand.Text = row[1].ToString();
}
}
}
I am new to Ajax. I am implementing a cascading dropdown in a telerik RadGrid.
I am adding the dropdownList and CascadingDropDown as follows:
DropDownList droplist = new DropDownList();
droplist.ID = "DropDownListOrderTask";
droplist.AutoPostBack = true;
item["OrderTask"].Controls.Add(droplist);
CascadingDropDown ccdOrderTask = new CascadingDropDown();
ccdOrderTask.ID = "ccdOrderTask";
ccdOrderTask.Category = "OrderTask";
ccdOrderTask.TargetControlID = "DropDownListOrderTask";
ccdOrderTask.PromptText = "Select Order Task";
ccdOrderTask.LoadingText = "Loading OrderTask";
ccdOrderTask.ServiceMethod = "BindOrderTask";
ccdOrderTask.ServicePath = "ajaxservice.asmx";
TextBox txt = (TextBox)item["TaskOwner"].Controls[0];
txt.Visible = false;
droplist = new DropDownList();
droplist.ID = "DropDownListTaskOwner";
item["TaskOwner"].Controls.Add(droplist);
CascadingDropDown ccdTaskOwner = new CascadingDropDown();
ccdTaskOwner.ID = "ccdTaskOwner";
ccdTaskOwner.Category = "TaskOwner";
ccdTaskOwner.ParentControlID = "DropDownListOrderTask";
ccdTaskOwner.TargetControlID = "DropDownListTaskOwner";
ccdTaskOwner.PromptText = "Select Task Owner";
ccdTaskOwner.LoadingText = "Loading Task Owner";
ccdTaskOwner.ServiceMethod = "BindTaskOwner";
ccdTaskOwner.ServicePath = "ajaxservice.asmx";
On the PreRender I have the following:
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
var ajaxManager = RadAjaxManager.GetCurrent(Page);
if(ajaxManager != null)
ajaxManager.AjaxSettings.AddAjaxSetting(this._UpdatePanel, this._RadGrid1, this._RadLoadingPanel);
}
In the ajaxservice.asmx I have the following:
[WebMethod]
public CascadingDropDownNameValue[] BindOrderTask(string knownCategoryValues, string category)
{
OrderRequestTaskTypeTable _orderRequestTaskTypeTable = new OrderRequestTaskType_List().ExecuteTypedDataTable();
List<CascadingDropDownNameValue> orderTaskDetails = new List<CascadingDropDownNameValue>();
foreach(DataRow dtRow in _orderRequestTaskTypeTable.Rows)
{
String orderTaskId = dtRow["OrderRequestTaskTypeId"].ToString();
String orderTaskName = dtRow["DescriptionTaskType"].ToString();
orderTaskDetails.Add(new CascadingDropDownNameValue(orderTaskId, orderTaskName));
}
return orderTaskDetails.ToArray();
}
The first dropDown, DropDownListOrderTask contains no values. On debugging through Firebug it says: ReferenceError: BindOrderTask is not defined
I am sure I am missing something but not sure what. Please help me.
I gave a Devexpress GridView which represent addresses. Two cascading combobox (Governorate- Area). When the user choose a Governorate the area combo will filtered according to the Governorate chased. When the user doesn't know the corresponding Governorate for the area, he only start by choosing the area and the governorate combobox will fill with the right governorate.
In index.chtml
<script type="text/javascript">
function governorateCombo_SelectedIndexChanged(s, e) {
areaCode.PerformCallback();
}
function AreaCombo_BeginCallback(s, e) {
e.customArgs['governorateCode'] = governorateCode.GetValue();
}
function areaCombo_SelectedIndexChanged(s, e) {
governorateCode.PerformCallback();
}
function GovernorateCombo_BeginCallback(s, e) {
e.customArgs['areaCode'] = areaCode.GetValue();
}
function GovernorateCombo_EndCallback(s, e) {
benGeoGridView.Refresh();
var bla = '#Session["governorateCode"]';
var item = s.FindItemByValue(bla);
s.SetSelectedItem(item);
}
ComboboxGovernoratePartial.chtml
#Html.DevExpress().ComboBox(settings =>
{
settings.CallbackRouteValues = new { Controller = "benFile", Action = "ComboBoxGovernoratePartial" };
settings.Name = "governorateCode";
settings.Properties.TextField = "governorateName1";
settings.Properties.ValueField = "governorateCode";
settings.Properties.ValueType = typeof(string);
settings.Width = 220;
settings.Properties.EnableSynchronization = DefaultBoolean.False;
settings.Properties.IncrementalFilteringMode = IncrementalFilteringMode.StartsWith;
if (Thread.CurrentThread.CurrentCulture.Name.Substring(0, 2) == "ar")
{
settings.RightToLeft = DefaultBoolean.True;
}
settings.Properties.ClientSideEvents.BeginCallback = "GovernorateCombo_BeginCallback";
settings.Properties.ClientSideEvents.SelectedIndexChanged = "governorateCombo_SelectedIndexChanged";
settings.Properties.ClientSideEvents.EndCallback = "GovernorateCombo_EndCallback";
}).BindList(Model).Bind(ViewData["governorateCode"]).GetHtml()
In controller:
public ActionResult ComboBoxGovernoratePartial()
{
string areaCode = (Request.Params["areaCode"] != null) ? Request.Params["areaCode"] : "-1";
List<governorateName> governorateNames = new List<governorateName>();
governorateMaster governorateMaster = new governorateMaster();
if (areaCode != null)
{
Session["governorateCode"] = Masters.areaMasters.First(a => a.areaCode == areaCode).governorateCode; ;
ViewData["governorateCode"] = Masters.areaMasters.First(a => a.areaCode == areaCode).governorateCode;
governorateNames = Masters.governorateNames.Where(a => a.langCode.ToLower() == Thread.CurrentThread.CurrentCulture.Name.Substring(0, 2)).ToList();
}
return PartialView(governorateNames.ToList());
}
When the user choose the area, (in js) I call perform call back for the governorate combobox that the controller pick up the right governorate to populate in the governorate combobox. The problem is that when I send the governorate code in a ViewData it is always null. In a Session varible, the value of it is the one at page load not the updated one in the controller.
Any suggestion ?
Sorry for your time guys
For that, you can try:
TempData["yourVar"]
i am using a datagridview in that i am using a datagridviewcomboboxcolumn, comboboxcolumn is displaying text but the problem is i want to select the first item of comboboxcolumn by default how can i do this
DataGridViewComboBoxColumn dgvcb = (DataGridViewComboBoxColumn)grvPackingList.Columns["PackingUnits"];
Globals.G_ProductUtility G_Utility = new Globals.G_ProductUtility();
G_Utility.addUnittoComboDGV(dgvcb);
DataSet _ds = iRawMaterialsRequest.SelectBMR(bmr_ID, branch_ID, "PACKING");
grvPackingList.DataSource = _ds.Tables[0];
int i = 0;
foreach (DataRow dgvr in _ds.Tables[0].Rows)
{
grvPackingList.Rows[i].Cells["Units"].Value = dgvr["Units"].ToString();
i++;
}
The values available in the combobox can be accessed via items property
row.Cells[col.Name].Value = (row.Cells[col.Name] as DataGridViewComboBoxCell).Items[0];
the best way to set the value of a datagridViewComboBoxCell is:
DataTable dt = new DataTable();
dt.Columns.Add("Item");
dt.Columns.Add("Value");
dt.Rows.Add("Item1", "0");
dt.Rows.Add("Item1", "1");
dt.Rows.Add("Item1", "2");
dt.Rows.Add("Item1", "3");
DataGridViewComboBoxColumn cmb = new DataGridViewComboBoxColumn();
cmb.DefaultCellStyle.Font = new Font("Tahoma", 8, FontStyle.Bold);
cmb.DefaultCellStyle.ForeColor = Color.BlueViolet;
cmb.FlatStyle = FlatStyle.Flat;
cmb.Name = "ComboColumnSample";
cmb.HeaderText = "ComboColumnSample";
cmb.DisplayMember = "Item";
cmb.ValueMember = "Value";
DatagridView dvg=new DataGridView();
dvg.Columns.Add(cmb);
cmb.DataSource = dt;
for (int i = 0; i < dvg.Rows.Count; i++)
{
dvg.Rows[i].Cells["ComboColumnSample"].Value = (cmb.Items[0] as
DataRowView).Row[1].ToString();
}
It worked with me very well
If I had known about doing it in this event, it would have saved me days of digging and
trial and errors trying to get it to set to the correct index inside the CellEnter event.
Setting the index of the DataGridViewComboBox is the solution I have been looking for.....THANKS!!!
In reviewing all the issues other coders have been experiencing with trying to set
the index inside of a DataGridViewComboBoxCell and also after looking over your code,
all that anyone really needs is:
1. Establish the event method to be used for the "EditingControlShowing" event.
2. Define the method whereby it will:
a. Cast the event control to a ComboBox.
b. set the "SelectedIndex" to the value you want.
In this example I simply set it to "0", but you'd probably want to apply so real life logic here.
Here's the code I used:
private void InitEvents()
{
dgv4.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler( dgv4EditingControlShowing );
}
private void dgv4EditingControlShowing( object sender, DataGridViewEditingControlShowingEventArgs e )
{
ComboBox ocmb = e.Control as ComboBox;
if ( ocmb != null )
{
ocmb.SelectedIndex = 0;
}
}
If DataGridViewComboBoxCell already exist:
DataTable dt = new DataTable();
dt.Columns.Add("Item");
dt.Columns.Add("Value");
dt.Rows.Add("Item 1", "0");
dt.Rows.Add("Item 2", "1");
dt.Rows.Add("Item 3", "2");
dt.Rows.Add("Item 4", "3");
for (int i = 0; i < dvg.Rows.Count; i++)
{
DataGridViewComboBoxCell comboCell = (DataGridViewComboBoxCell)dvg.Rows[i].Cells[1];
comboCell.DisplayMember = "Item";
comboCell.ValueMember = "Value";
comboCell.DataSource = dt;
};
I've had some real trouble with ComboBoxes in DataGridViews and did not find an elegant way to select the first value. However, here is what I ended up with:
public static void InitDGVComboBoxColumn<T>(DataGridViewComboBoxCell cbx, List<T> dataSource, String displayMember, String valueMember)
{
cbx.DisplayMember = displayMember;
cbx.ValueMember = valueMember;
cbx.DataSource = dataSource;
if (cbx.Value == null)
{
if(dataSource.Count > 0)
{
T m = (T)cbx.Items[0];
FieldInfo fi = m.GetType().GetField(valueMember, BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
cbx.Value = fi.GetValue(m);
}
}
}
It basically sets the .Display and .ValueMember properties of the DataGridViewComboBoxCell and uses a List as DataSource. It then takes the first item, and uses reflection to get the value of the member that was used as ValueMember and sets the selected value via .Value
Use it like this:
public class Customer
{
private String name;
public String Name
{
get {return this.name; }
set {this.name = value; }
}
private int id;
public int Id
{
get {return this.id; }
set {this.id = value; }
}
}
public class CustomerCbx
{
private String display;
public String Display
{
get {return this.display; }
set {this.display = value; }
}
private Customer value;
public Customer Value
{
get {return this.value; }
set {this.value = value; }
}
}
public class Form{
private void Form_OnLoad(object sender, EventArgs e)
{
//init first row in the dgv
if (this.dgv.RowCount > 0)
{
DataGridViewRow row = this.dgv.Rows[0];
DataGridViewComboBoxCell cbx = (DataGridViewComboBoxCell)row.Cells[0];
Customer c1 = new Customer(){ Name = "Max Muster", ID=1 };
Customer c2 = new Customer(){ Name = "Peter Parker", ID=2 };
List<CustomerCbx> custList = new List<CustomerCbx>()
{
new CustomerCbx{ Display = c1.Name, Value = c1},
new CustomerCbx{ Display = c2.Name, Value = c2},
}
InitDGVComboBoxColumn<CustomerCbx>(cbx, custList, "display", "value");
}
}
}
}
It seems pretty hacky to me, but I couldn't find any better way so far (that also works with complex objects other than just Strings). Hope that will save the search for some others ;)
You need to set the Items for the new cell. This must be auto done by the column when creating a new row from the UI.
var cell = new DataGridViewComboBoxCell() { Value = "SomeText" };
cell.Items.AddRange(new String[]{"SomeText", "Abcd", "123"});
something different worked for me what i did is to simply set the value of dtataGridComboBox when ever new record is added bu user with 'userAddedRow' event. For the first row I used the code in constructor.
public partial class pt_drug : PatientDatabase1_3._5.basic_templet
{
public pt_drug()
{
InitializeComponent();
dataGridView_drugsDM.Rows[0].Cells[0].Value = "Tablet";
}
private void dataGridView_drugsDM_UserAddedRow(object sender, DataGridViewRowEventArgs e)
{
dataGridView_drugsDM.Rows[dataGridView_drugsDM.RowCount - 1].Cells[0].Value = "Tablet";
}
}
Here the solution I have found : select the cell you are interested in so you can cast it to a combobox.
this.Invoke((MethodInvoker)delegate
{
this.dataGridView1.CurrentCell = dataGridView1.Rows[yourRowindex].Cells[yourColumnIndex];
this.dataGridView1.BeginEdit(true);
ComboBox comboBox = (ComboBox)this.dataGridView1.EditingControl;
comboBox.SelectedIndex += 1;
});