Search Results

Search found 45 results on 2 pages for 'datarowview'.

Page 1/2 | 1 2  | Next Page >

  • Please help with 'System.Data.DataRowView' does not contain a property with the name...

    - by Catalin
    My application works just fine until, in some unidentified conditions, it begins throwing this errors: When these errors start appearing, they appear in all over the application, no matter the code is built using ObjectDataSource or SqlDataSource. However, apparently, if the code uses some "classic", code-behind data-binding, that code does not throw errors (they do not show in the application event log), the page is displayed but it does not contain any data.... Please HELP tracking these very strange errors !!!!!! Here is the error log from the Event Viewer Exception information: Exception type: HttpUnhandledException Exception message: Exception of type 'System.Web.HttpUnhandledException' was thrown. Request information: Request URL: http://SITE/agsis/Default.aspx?tabid=1281&error=DataBinding5/7/2009 10:23:03 AMa+'System.Data.DataRowView'+does+not+contain+a+property+with+the+name+'DenumireMaterie'. Request path: /agsis/Default.aspx User host address: 299.299.299.299 ;) User: georgeta Is authenticated: True Authentication Type: Forms Thread account name: NT AUTHORITY\NETWORK SERVICE Thread information: Thread ID: 1 Thread account name: NT AUTHORITY\NETWORK SERVICE Is impersonating: False Stack trace: at System.Web.UI.Page.HandleError(Exception e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequest(HttpContext context) at ASP.errorpage_aspx.ProcessRequest(HttpContext context) at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) Here is the error log from my application: AssemblyVersion: 04.05.01 PortalID: 18 PortalName: Stiinte Economice UserID: 85 UserName: georgeta ActiveTabID: 1281 ActiveTabName: Plan Invatamant RawURL: /agsis/Default.aspx?tabid=1281&error=DataBinding%3a+'System.Data.DataRowView'+does+not+contain+a+property+with+the+name+'DenumireMaterie'. AbsoluteURL: /agsis/Default.aspx AbsoluteURLReferrer: http://SITE/agsis/Default.aspx?tabid=1281&ctl=Login&returnurl=%2fagsis%2fDefault.aspx%3ftabid%3d1281%26ctl%3dNotePlanSemestru%26mid%3d2801%26ID_PlanSemestru%3d518%26ID_PlanInvatamant%3d304%26ID_FC%3d206%26ID_FCForma%3d85%26ID_Domeniu%3d418%26ID_AnStudiu%3d7%26ID_Specializare%3d6522%26ID_AnUniv%3d27 UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SIMBAR={8C326639-C677-4045-B6D9-F59C330790E7}) DefaultDataProvider: DotNetNuke.Data.SqlDataProvider, DotNetNuke.SqlDataProvider ExceptionGUID: c56dc33e-973f-467a-a90d-2a8fc7193aec InnerException: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'ID_PlanInvatamant'. FileName: FileLineNumber: 0 FileColumnNumber: 0 Method: System.Web.UI.DataBinder.GetPropertyValue StackTrace: Message: DotNetNuke.Services.Exceptions.PageLoadException: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'ID_PlanInvatamant'. --- System.Web.HttpException: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'ID_PlanInvatamant'. at System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName) at System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) at System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) at System.Web.UI.WebControls.DataBoundControl.PerformSelect() at System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() at System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() at System.Web.UI.Control.EnsureChildControls() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) --- End of inner exception stack trace --- Source: Server Name: SERVER2 Thank you, Catalin

    Read the article

  • How to bind a datatable to a wpf editable combobox: selectedItem showing System.Data.DataRowView

    - by black sensei
    Hello Good People!! I bound a datatable to a combobox and defined a dataTemplate in the itemTemplate.i can see desired values in the combobox dropdown list,what i see in the selectedItem is System.Data.DataRowView here are my codes: <ComboBox Margin="128,139,123,0" Name="cmbEmail" Height="23" VerticalAlignment="Top" TabIndex="1" ToolTip="enter the email you signed up with here" IsEditable="True" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding}"> <ComboBox.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock Text="{Binding Path=username}"/> </StackPanel> </DataTemplate> </ComboBox.ItemTemplate> The code behind is so : if (con != null) { con.Open(); //users table has columns id | username | pass SQLiteCommand cmd = new SQLiteCommand("select * from users", con); SQLiteDataAdapter da = new SQLiteDataAdapter(cmd); userdt = new DataTable("users"); da.Fill(userdt); cmbEmail.DataContext = userdt; } I've been looking for something like SelectedValueTemplate or SelectedItemTemplate to do the same kind of data templating but i found none. I'll like to ask if i'm doing something wrong or it's a known issue for combobox binding? if something is wrong in my code please point me to the right direction. thanks for reading this

    Read the article

  • Databinding gives "System.Data.DataRowView" instead of actual values

    - by iTayb
    This is my code: string SQL = "SELECT email FROM members WHERE subscribe=true"; string myConnString = Application["ConnectionString"].ToString(); OleDbConnection myConnection = new OleDbConnection(myConnString); OleDbCommand myCommand = new OleDbCommand(SQL, myConnection); myConnection.Open(); OleDbDataAdapter MyAdapter = new OleDbDataAdapter(myCommand); DataSet ds = new DataSet(); MyAdapter.Fill(ds); MailsListBox.DataSource = ds; MailsListBox.DataBind(); GridView1.DataSource = ds; GridView1.DataBind(); myConnection.Close(); And so it looks: As you see, the GridView shows the dataset just fine, and the ListBox fails it. What happened? How can I fix it? Thank you very much.

    Read the article

  • How can the DataView object reference not be set?

    - by dboarman-FissureStudios
    I have the following sample where the SourceData class would represent a DataView resulting from an Sql query: class MainClass { private static SourceData Source; private static DataView View; private static DataView Destination; public static void Main (string[] args) { Source = new SourceData(); View = new DataView(Source.Table); Destination = new DataView(); Source.AddRowData("Table1", 100); Source.AddRowData("Table2", 1500); Source.AddRowData("Table3", 1300324); Source.AddRowData("Table4", 1122494); Source.AddRowData("Table5", 132545); Console.WriteLine(String.Format("Data View Records: {0}", View.Count)); foreach(DataRowView drvRow in View) { Console.WriteLine(String.Format("Source {0} has {1} records.", drvRow["table"], drvRow["records"])); DataRowView newRow = Destination.AddNew(); newRow["table"] = drvRow["table"]; newRow["records"] = drvRow["records"]; } Console.WriteLine(); Console.WriteLine(String.Format("Destination View Records: {0}", Destination.Count)); foreach(DataRowView drvRow in Destination) { Console.WriteLine(String.Format("Destination {0} has {1} records.", drvRow["table"], drvRow["records"])); } } } class SourceData { public DataTable Table { get{return dataTable;} } private DataTable dataTable; public SourceData() { dataTable = new DataTable("TestTable"); dataTable.Columns.Add("table", typeof(string)); dataTable.Columns.Add("records", typeof(int)); } public void AddRowData(string tableName, int tableRows) { dataTable.Rows.Add(tableName, tableRows); } } My output is: Data View Records: 5 Source Table1 has 100 records. Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object at System.Data.DataView.AddNew () [0x0003e] in /usr/src/packages/BUILD/mono-2.4.2.3 /mcs/class/System.Data/System.Data/DataView.cs:344 at DataViewTest.MainClass.Main (System.String[] args) [0x000e8] in /home/david/Projects/DataViewTest/SourceData.cs:29 I did some reading here: DataView:AddNew Method... ...and it would appear that I am doing this the right way. How come I am getting the Object reference not set?

    Read the article

  • Insert a Row with a sorted DataGridView

    - by Ruben Trancoso
    My DataGridView is bound to the same BindingSource as the Insert Form, and the Name column is sorted. After insert is done, the groupBindingSource.Current is not returning the new inserted DataRowView but the last row in the sort order what makes the Update do nothing. FormGroup formGroup = new FormGroup(); formGroup .Source = groupBindingSource; formGroup .setMode(FormGroup.Mode.Insert); if (formGroup .ShowDialog() == DialogResult.OK) { DataRowView drv = (DataRowView)groupBindingSource.Current; grupoTableAdapter.Update(drv.Row); }

    Read the article

  • How to maintain ComboBox.SelectedItem reference when DataSource is resorted?

    - by Dave
    This really seems like a bug to me, but perhaps some databinding gurus can enlighten me? (My WinForms databinding knowledge is quite limited.) I have a ComboBox bound to a sorted DataView. When the properties of the items in the DataView change such that items are resorted, the SelectedItem in my ComboBox does not keep in-sync. It seems to point to someplace completely random. Is this a bug, or am I missing something in my databinding? Here is a sample application that reproduces the problem. All you need is a Button and a ComboBox: public partial class Form1 : Form { private DataTable myData; public Form1() { this.InitializeComponent(); this.myData = new DataTable(); this.myData.Columns.Add("ID", typeof(int)); this.myData.Columns.Add("Name", typeof(string)); this.myData.Columns.Add("LastModified", typeof(DateTime)); this.myData.Rows.Add(1, "first", DateTime.Now.AddMinutes(-2)); this.myData.Rows.Add(2, "second", DateTime.Now.AddMinutes(-1)); this.myData.Rows.Add(3, "third", DateTime.Now); this.myData.DefaultView.Sort = "LastModified DESC"; this.comboBox1.DataSource = this.myData.DefaultView; this.comboBox1.ValueMember = "ID"; this.comboBox1.DisplayMember = "Name"; } private void saveStuffButton_Click(object sender, EventArgs e) { DataRowView preUpdateSelectedItem = (DataRowView)this.comboBox1.SelectedItem; // OUTPUT: SelectedIndex = 0; SelectedItem.Name = third Debug.WriteLine(string.Format("SelectedIndex = {0:N0}; SelectedItem.Name = {1}", this.comboBox1.SelectedIndex, preUpdateSelectedItem["Name"])); this.myData.Rows[0]["LastModified"] = DateTime.Now; DataRowView postUpdateSelectedItem = (DataRowView)this.comboBox1.SelectedItem; // OUTPUT: SelectedIndex = 2; SelectedItem.Name = second Debug.WriteLine(string.Format("SelectedIndex = {0:N0}; SelectedItem.Name = {1}", this.comboBox1.SelectedIndex, postUpdateSelectedItem["Name"])); // FAIL! Debug.Assert(object.ReferenceEquals(preUpdateSelectedItem, postUpdateSelectedItem)); } }

    Read the article

  • DataGridView selectedRow Property not get Data if i double click Row?

    - by programmerist
    i click double dataGridView's any row. Not get Data clicked row data: private void gwStudies_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { GoruntuyuAc(); } private void GoruntuyuAc() { olduid = ""; DataRowView ro = (gwStudies.SelectedRows[0].DataBoundItem as DataRowView); string uid = ""; uid = ro["StudyInstanceUid"].ToString(); string tarih = ""; DateTime t1 = Convert.ToDateTime(ro["StudyDate"]); //........ //............ } Error Data on (gwStudies.SelectedRows[0].DataBoundItem as DataRowView); IMAGE:

    Read the article

  • ASP.Net check value with DBNULL

    - by c11ada
    hey all, i have the following code foreach (DataRowView dr in Data) { if (dr == System.DBNull.Value) { nedID = 1; } } but i get the following error Operator '==' cannot be applied to operands of type 'System.Data.DataRowView' and 'System.DBNull' please can some one advice me on how i can check if the value is null or DBNULL

    Read the article

  • add row to a BindingSource gives different autoincrement value from whats saved into DB

    - by Ruben Trancoso
    I have a DataGridView that shows list of records and when I hit a insert button, a form should add a new record, edit its values and save it. I have a BindingSource bound to a DataGridView. I pass is as a parameter to a NEW RECORD form so // When the form opens it add a new row and de DataGridView display this new record at this time DataRowView currentRow; currentRow = (DataRowView) myBindindSource.AddNew(); when user confirm to save it I do a myBindindSource.EndEdit(); // inside the form and after the form is disposed the new row is saved and the bindingsorce position is updated to the new row DataRowView drv = myForm.CurrentRow; avaliadoTableAdapter.Update(drv.Row); avaliadoBindingSource.Position = avaliadoBindingSource.Find("ID", drv.Row.ItemArray[0]); The problem is that this table has a AUTOINCREMENT field and the value saved may not correspond the the value the bindingSource gives in EDIT TIME. So, when I close and open the DataGridView again the new rowd give its ID based on the available slot in the undelying DB at the momment is was saved and it just ignores the value the BindingSource generated ad EDIT TIME, Since the value given by the binding source should be used by another table as a foreingKey it make the reference insconsistent. There's a way to get the real ID was saved to the database?

    Read the article

  • Select newly added Row - DataGridView and BindingSource

    - by Ruben Trancoso
    I'm adding a new Row to a BindingSource that is Bound to a DataGridView source.AddNew(); After this, use BindingSource to get the newly added row is return the next row in the DataGridView when its sorted. ROW "A" ROW "B" <- myBindingSource.AddNew(); ROW "C" myBindingSource.Current gives ROW "C". (it became the selected row in the DataGridView) I need this because I want to update just the newly added row DataRowView drv = (DataRowView)myBindingSource.Current; myTableAdapter.Update(drv.Row); and not the entire table. myTableAdapter.Update(myDataSet.myTable); and also, I would like to have this newly added line selected in the DataGridView after insertion. is it possible in some way?

    Read the article

  • I have Following code but rest of it how?

    - by Hakan
    I have following code which is putting value of text box to table but i can't manage how to delete record. Can someone help me about it? Dim meter As DataTable = Me.DataSet1.Tables.Item("tblmeter") Dim row As DataRow = meter.NewRow() row.Item("No") = Me.txtno.Text row.Item("Turnover") = Me.txtturnover.Text row.Item("Total Win") = Me.txttotalwin.Text row.Item("Games Played") = Me.txtgamesplayed.Text row.Item("Credit In") = Me.txtcreditin.Text row.Item("Bill In") = Me.txtbillin.Text row.Item("Hand Pay") = Me.txthandpay.Text row.Item("Date") = DateTime.Today.ToShortDateString meter.Rows.Add(row) Me.TblMeterTableAdapter.Update(Me.DataSet1.tblMeter) meter.AcceptChanges() Dim table As DataTable = Me.DataSet1.Tables.Item("tblmeter") Dim defaultView As DataView = table.DefaultView Dim cell As New DataGridCell((defaultView.Table.Rows.Count - 1), 1) Me.DataGrid1.CurrentCell = cell txtno.Text = "" txtturnover.Text = "" txttotalwin.Text = "" txtgamesplayed.Text = "" txtcreditin.Text = "" txtbillin.Text = "" txthandpay.Text = "" txtno.Focus() I am using following code but it's not update records. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim current As DataRowView = DirectCast(Me.BindingContext.Item(Me.DataSet1.Tables.Item("tblmeter")).Current, DataRowView) current.Delete() Me.DataSet1.tblMeter.AcceptChanges() Me.TblMeterTableAdapter.Update(Me.DataSet1.tblMeter) End Sub Code deletes records from datagrid but not updating. Any help

    Read the article

  • datalist itemdatabound event having issues changing item bg color on condition

    - by Jreeter
    Hey guys I'm trying to do something really simple.. I'm checking a data column in my datarow if it's 0 I want the item back color in the datalist to be green if its < 0 remain transparent... if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { DataRowView drv = (DataRowView)(e.Item.DataItem); int rating = int.Parse(drv.Row["rating"].ToString()); if (rating > 0) { e.Item.BackColor = System.Drawing.Color.Green; } } I've stepped through with debugger and it's hitting all the conditions the color just isn't changing.. I know it has to be something simple I just can't see it.

    Read the article

  • Method params match signature, but still getting error

    - by Jason
    I am in the midst of converting a VB library to C#. One of my methods has the following signature in VB: Private Shared Sub FillOrder(ByVal row As DataRowView, ByRef o As Order) In C# I converted it to: private static void FillOrder(DataRowView row, ref Order o) From my constructor inside my Order class, I am calling the FillOrder() method like so: DataView dv = //[get the data] if (dv.Count > 0) { FillOrder(dv[0], this); } In VB, this works: Dim dv As DataView = '[get data]' If dv.Count > 0 Then FillOrder(dv.Item(0), Me) End If However, in VS10 in the C# file I am getting a red squiggle under this call with the following error: The best overloaded method match for [the method] has some invalid arguments This was working code in VB. What am I doing wrong?

    Read the article

  • how to create property of type generic class?

    - by Anish
    public class SelectionList<T> : ObservableCollection<SelectionItem<T>> where T : IComparable<T> { // Code } public class SelectionItem<T> : INotifyPropertyChanged { // Code } I need to create a property which is of the type SelectionList...as follows: public SelectionList<string> Sports { get; set; }. But when I replace string with DataRowView, as public SelectionList<DataRowView> Sports { get; set; }. I am getting error. Please help

    Read the article

  • Cloning items in a listbox c#

    - by Jenny
    I have 2 list boxes and want to be able to copy selected items from one to the other how ever many times I want. Ive managed to do this but I have buttons on the 2nd list box that allow me to go up and down..Now when theres to items in the second list box that are the same (e.g "gills" and "gills") it doesnt behave normally and crashes. Is there a way in which I can get them to act as seperate items in the 2nd listbox? code private void buttonUp_Click(object sender, EventArgs e) { object selected = listBox2.SelectedItem; int index = list2.Items.IndexOf(selected); listBox2.Items.Remove(selected); listBox2.Items.Insert(index - 1, selected); listBox2.SetSelected(index - 1, true); } private void buttonAdd_Click(object sender, EventArgs e) { DataRowView selected = (DataRowView)listBox1.SelectedItem; string item = selected["title"].ToString(); listBox2.Items.Add(item); } It works fine when i havnt got duplicates but when i do they just jump around randomly when i press up/down. (ive not included down as its pretty much the same as up)

    Read the article

  • using the ASP.NET Caching API via method annotations in C#

    - by craigmoliver
    In C#, is it possible to decorate a method with an annotation to populate the cache object with the return value of the method? Currently I'm using the following class to cache data objects: public class SiteCache { // 7 days + 6 hours (offset to avoid repeats peak time) private const int KeepForHours = 174; public static void Set(string cacheKey, Object o) { if (o != null) HttpContext.Current.Cache.Insert(cacheKey, o, null, DateTime.Now.AddHours(KeepForHours), TimeSpan.Zero); } public static object Get(string cacheKey) { return HttpContext.Current.Cache[cacheKey]; } public static void Clear(string sKey) { HttpContext.Current.Cache.Remove(sKey); } public static void Clear() { foreach (DictionaryEntry item in HttpContext.Current.Cache) { Clear(item.Key.ToString()); } } } In methods I want to cache I do this: [DataObjectMethod(DataObjectMethodType.Select)] public static SiteSettingsInfo SiteSettings_SelectOne_Name(string Name) { var ck = string.Format("SiteSettings_SelectOne_Name-Name_{0}-", Name.ToLower()); var dt = (DataTable)SiteCache.Get(ck); if (dt == null) { dt = new DataTable(); dt.Load(ModelProvider.SiteSettings_SelectOne_Name(Name)); SiteCache.Set(ck, dt); } var info = new SiteSettingsInfo(); foreach (DataRowView dr in dt.DefaultView) info = SiteSettingsInfo_Load(dr); return info; } Is it possible to separate those concerns like so: (notice the new annotation) [CacheReturnValue] [DataObjectMethod(DataObjectMethodType.Select)] public static SiteSettingsInfo SiteSettings_SelectOne_Name(string Name) { var dt = new DataTable(); dt.Load(ModelProvider.SiteSettings_SelectOne_Name(Name)); var info = new SiteSettingsInfo(); foreach (DataRowView dr in dt.DefaultView) info = SiteSettingsInfo_Load(dr); return info; }

    Read the article

  • how to make changes to database in WPF?

    - by user353573
    Drag access database into designer xsd, toolkit:datagrid get datacontext from resources correctly show the table content through this binding. Press button in the button column, can show each row correctly. delete row and add row also work in datagrid however, when i press button column to add a new row or delete a row, there is no change in the underlying database, how to commit the changes from datagrid to database in WPF if not using ADO.net ? The following code is what i try do not work private void datagrid2_delete(object sender, RoutedEventArgs e) { Button showButton = (Button)sender; //person p = (person)showButton.DataContext; DataRowView ds = (DataRowView)showButton.DataContext; //DataSet1.customertableRow p = (DataSet1.customertableRow)ds; //ds.BeginEdit(); //ds.Delete(); //ds.EndEdit(); /* DataSourceProvider provider = (DataSourceProvider)this.FindResource("Family"); WpfApplication1.DataSet1.customertableDataTable table = (WpfApplication1.DataSet1.customertableDataTable)provider.Data; table.AddcustomertableRow("hello3", 5, System.DateTime.Today); table.AcceptChanges(); }

    Read the article

  • unhandeled exception occured in c#

    - by abid
    hey. i`m getting this error that system.data.datarowview is not permitted in this contexxt. valid expressions are constants expressions and ( in some contexts). column name are not permitted.. can any body guide me what this error says.. can any one provide me a suggestion whether where im wrong.. any guesses guys??? im not getting it.. :/

    Read the article

  • unhandled exception occured in c#

    - by abid
    hey. i`m getting this error that system.data.datarowview is not permitted in this contexxt. valid expressions are constants expressions and ( in some contexts). column name are not permitted.. can any body guide me what this error says.. can any one provide me a suggestion whether where im wrong.. any guesses guys??? im not getting it.. :/

    Read the article

  • Unselect Databound Combobox Winforms .NET

    - by joedotnot
    The problem: combobox is databound to a DataView, first item in the dataview is DataRowView whose fields are DBNull.Value; Combo DropdownStyle = ComboBoxStyle.DropDownList Loads fine, displays fine, selects fine, problem is to Unselect via code. Setting the SelectedIndex to 0 throws an exception. (Setting to -1 is a no-no as per msdn doco that says dont set SelectedIndex=-1 if databound) So how to unselect without throwing an exception ? For now i wrapped it into a try/catch to just ignore the error! EDIT: As asked by Hubeza, i worked on sample code to post. Did a stripped down version of the original code in C# (original is in VB.NET) and could NOT reproduce it either. Converted to VB.NET and could NOT reproduce it either ! In other words, SelectedIndex = 0 does work in the stripped down version! Currently further investigating what else could be wrong with the original code. EDIT2: Case Closed. Call me a stupid fool if you like, and apologies for wasting anyone's time - The error was originating from MyComboBox_SelectedIndexChanged event, which i neglected to check ! May as well post the sample in case anyone finds useful. private void LoadComboMethod() { DataTable dtFruit = new DataTable("FruitTable"); //define columns DataColumn colID = new DataColumn(); colID.DataType = typeof(Int32); //VB.NET GetType(Int32) colID.ColumnName = "ID"; DataColumn colDesc = new DataColumn(); colDesc.DataType = typeof(String); colDesc.ColumnName = "Description"; //add columns to table dtFruit.Columns.AddRange(new DataColumn[] { colID, colDesc }); //add rows DataRow row = dtFruit.NewRow(); row[colID] = 1; row[colDesc] = "Apples"; dtFruit.Rows.Add(row); row = dtFruit.NewRow(); row[colID] = 1; row[colDesc] = "Bananas"; dtFruit.Rows.Add(row); row = dtFruit.NewRow(); row[colID] = 1; row[colDesc] = "Oranges"; dtFruit.Rows.Add(row); //add extra blank row. DataRowView drv = dtFruit.DefaultView.AddNew(); drv.EndEdit(); //Bind combo box DataView dv = new DataView(dtFruit); dv.Sort = "ID ASC"; //ensure blank item on top cboFruit.DataSource = dv; cboFruit.DisplayMember = "Description"; cboFruit.ValueMember = "ID"; } private void UnselectComboMethod() { if (cboFruit.SelectedIndex > 0) { cboFruit.SelectedIndex = 0; } else { MessageBox.Show("no fruit selected"); } }

    Read the article

  • Proper binding data to combobox and handling its events.

    - by Wodzu
    Hi guys. I have a table in SQL Server which looks like this: ID Code Name Surname 1 MS Mike Smith 2 JD John Doe 3 UP Unknown Person and so on... Now I want to bind the data from this table into the ComboBox in a way that in the ComboBox I have displayed value from the Code column. I am doing the binding in this way: SqlDataAdapter sqlAdapter = new SqlDataAdapter("SELECT * FROM dbo.Users ORDER BY Code", MainConnection); sqlAdapter.Fill(dsUsers, "Users"); cbxUsers.DataSource = dsUsers.Tables["Users"]; cmUsers = (CurrencyManager)cbxUsers.BindingContext[dsUsers.Tables["Users"]]; cbxUsers.DisplayMember = "Code"; And this code seems to work. I can scroll through the list of Codes. Also I can start to write code by hand and ComboBox will autocomplete the code for me. However, I wanted to put a label at the top of the combobox to display Name and Surname of the currently selected user code. My line of though was like that: "So, I need to find an event which will fire up after the change of code in combobox and in that event I will get the current DataRow..." I was browsing through the events of combobox, tried many of them but without a success. For example: private void cbxUsers_SelectionChangeCommitted(object sender, EventArgs e) { if (cmUsers != null) { DataRowView drvCurrentRowView = (DataRowView)cmUsers.Current; DataRow drCurrentRow = drvCurrentRowView.Row; lblNameSurname.Text = Convert.ToString(drCurrentRow["Name"]) + " " + Convert.ToString(drCurrentRow["Surname"]); } } This give me a strange results. Firstly when I scroll via mouse scroll it doesn't return me the row wich I am expecting to obtain. For example on JD it shows me "Mike Smith", on MS it shows me "John Doe" and on UP it shows me "Mike Smith" again! The other problem is that when I start to type in ComboBox and press enter it doesn't trigger the event. However, everything works as expected when I bind data to lblNameSurname.Text in this way: lblNameSurname.DataBindings.Add("Text", dsusers.Tables["Users"], "Name"); The problem here is that I can bind only one column and I want to have two. I don't want to use two labels for it (one to display name and other to display surname). So, what is the solution to my problem? Also, I have one question related to the data selection in ComboBox. Now, when I type something in the combobox it allows me to type letters that are not existing in the list. For example, I start to type "J" and instead of finishing with "D" so I would have "JD", I type "Jsomerandomtexthere". Combobox will allow that but such item does not exists on the list. In other words, I want combobox to prevent user from typing code which is not on the list of codes. Thanks in advance for your time.

    Read the article

  • RadioButton checkedchanged event firing multiple times

    - by kash3
    Hi, I am trying to add multiple radiobutton columns to my gridview dynamically in the code and i want to implement some logic which involves database fetch in the checkedchanged event of radiobuttons but some how the checked changed event is being fired multiple times for each row. Following is the code: aspx: <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#CC9966" BorderStyle="None" EnableViewState="true" BorderWidth="1px" CellPadding="4" Font-Names="Verdana"> <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" /> <Columns> <asp:TemplateField HeaderText="Select One"> <ItemTemplate> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Select Two"> <ItemTemplate> </ItemTemplate> </asp:TemplateField> <asp:TemplateField> <ItemTemplate> <asp:Label ID="lblval" runat="server" Text="!" ForeColor="Red" Visible="false"/> </ItemTemplate> </asp:TemplateField> </Columns> **code behind** void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.DataItem != null) { DataRowView dvRowview = (DataRowView)e.Row.DataItem; int currentRow = GridView1.Rows.Count; RadioButton rdoSelect1 = new RadioButton(); rdoSelect1.GroupName = "Select" + currentRow; rdoSelect1.ID = string.Concat("rdoSelect1", currentRow); rdoSelect1.AutoPostBack = true; rdoSelect1.CheckedChanged += new EventHandler(rdoSelect_CheckedChanged); e.Row.Cells[0].Controls.Add(rdoSelect1); RadioButton rdoSelect2 = new RadioButton(); rdoSelect2.GroupName = "Select" + currentRow; rdoSelect2.ID = string.Concat("rdoSelect2", currentRow); rdoSelect2.AutoPostBack = true; rdoSelect2.CheckedChanged += new EventHandler(rdoSelect_CheckedChanged); e.Row.Cells[1].Controls.Add(rdoSelect2); if (!IsPostBack) { e.Row.Cells[e.Row.Cells.Count - 1].Controls[1].Visible = false; if (e.Row.Cells[0] != null && Convert.ToBoolean(dvRowview["Select1"]) == true) rdoSelect1.Checked = true; else rdoSelect1.Checked = false; if (e.Row.Cells[0] != null && Convert.ToBoolean(dvRowview["Select2"]) == true) rdoSelect2.Checked = true; else rdoSelect2.Checked = false; } } } void rdoSelect_CheckedChanged(object sender, EventArgs e) { RadioButton rdoSelectedOption = (RadioButton)sender; GridViewRow selRow = rdoSelectedOption.NamingContainer as GridViewRow; if (rdoSelectedOption.Checked) selRow.Cells[selRow.Cells.Count - 1].Controls[1].Visible = true; else selRow.Cells[selRow.Cells.Count - 1].Controls[1].Visible = false; } i want the checkedchanged event to fire only once for a group name and row.

    Read the article

  • Transferring data from one list box to another c#

    - by Jenny
    Hi, Ok so I have 2 list boxes one is connected to a database the other isnt. I want to be able to send the selected item from the listbox connected to the database to the one that isnt. Ive written this code listBox2.Items.Add(listBox1.SelectedItem); But instead of copyin the item i get " System.Data.DataRowView Anyone havin any advice?

    Read the article

1 2  | Next Page >