Search Results

Search found 2511 results on 101 pages for 'datagridview trick'.

Page 7/101 | < Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >

  • Datagridview retains waitcursor when updated from thread

    - by Apeksha
    I have a DataGridView control in my Windows Forms Application. I am adding rows to the grid using a background thread. I change the form's cursor to Waitcursor when the process starts and back to Default when it ends. This works well for the form, but not for the grid. When the form's cursor is changed back to default, the grid's cursor does not change, although the cursor over the rest of the form does. Does this have anything to do with the fact that I am updating the grid from a background thread? (The cursor is being changed from the UI thread).

    Read the article

  • how to get the value entered in combobox that is binded to datagridview

    - by Ranjana
    i have dynamically added combobox to datagridview. in this gridview i need to enter the values to combobox. but it is not allowing me to enter the value. code: if (strtype.Contains("ComboBox")) { checkcmbColumn.Name = strControlName; checkcmbColumn.HeaderText = strColumnName; checkcmbColumn.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; checkcmbColumn.Width = 100; checkcmbColumn.ReadOnly = false; checkcmbColumn.Items.Add("1"); checkcmbColumn.Items.Add("2"); GrdViewDetails.Columns.Add(checkcmbColumn); }

    Read the article

  • DataGridView - DefaultCellStyle, rows and columns propriority

    - by angelPL
    Hi! In C#, in DataGridView I want to set the BackColor property for the first row and first column. And the cell from first row and first column, should have property from first column, not row - but it does. For example: (table 3 x 3); 'X' - property for first row, 'Y' - property for first column, 'a' - default property should be: Y X X Y a a Y a a but is: X X X Y a a Y a a There is no matter which property I set first: dataGridView1.Rows[0].DefaultCellStyle.BackColor = Color.Lavender; dataGridView1.Columns[0].DefaultCellStyle.BackColor = Color.Beige; or: dataGridView1.Columns[0].DefaultCellStyle.BackColor = Color.Beige; dataGridView1.Rows[0].DefaultCellStyle.BackColor = Color.Lavender; Sorry for my english...

    Read the article

  • C# - Saving a DataGridView to file and loading

    - by Rekar
    Hello, To start off, what I have is a simple Winforms app, with just a save and load button, and with a datagridview control to hold data. What I am looking to do is input some data into the control, hit the save button, and it save all the data to a file locally on the computer, and when I hit load, it loads the file and populates the control appropriately, keeping all rows, columns, and data the same as when saved. Although it sounds fairly simple to me, I cant seem to figure a good way to save and load the data. Can I get a few pointers or examples to get myself started? Thank you.

    Read the article

  • When i am adding eventHandler on combo in datagridview, its adding eventHandler to all other combo o

    - by Rajesh Rolen- DotNet Developer
    i am using VS2005 (c#.net desktop application). when i am adding eventHandler to a combo of datagridview, its automatically adding same eventhandler to all other combos of same datagridview.. my code: private void dgvtstestdetail_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { DataGridView grid = (sender as DataGridView); if (grid.CurrentCell.OwningColumn == grid.Columns["gdvtstd_TestParameter"]) { ComboBox cb = (e.Control as ComboBox); cb.SelectedIndexChanged -= new EventHandler(dvgCombo_SelectedIndexChanged); cb.SelectedIndexChanged += new EventHandler(dvgCombo_SelectedIndexChanged); } }

    Read the article

  • NHibernate, Databinding to DataGridView, Lazy Loading, and Session managment - need advice

    - by Tom Bushell
    My main application form (WinForms) has a DataGridView, that uses DataBinding and Fluent NHibernate to display data from a SQLite database. This form is open for the entire time the application is running. For performance reasons, I set the convention DefaultLazy.Always() for all DB access. So far, the only way I've found to make this work is to keep a Session (let's call it MainSession) open all the time for the main form, so NHibernate can lazy load new data as the user navigates with the grid. Another part of the application can run in the background, and Save to the DB. Currently, (after considerable struggle), my approach is to call MainSession.Disconnect(), create a disposable Session for each Save, and MainSession.Reconnect() after finishing the Save. Otherwise SQLite will throw "The database file is locked" exceptions. This seems to be working well so far, but past experience has made me nervous about keeping a session open for a long time (I ran into performance problems when I tried to use a single session for both Saves and Loads - the cache filled up, and bogged down everything - see http://stackoverflow.com/questions/2526675/commit-is-very-slow-in-my-nhibernate-sqlite-project). So, my question - is this a good approach, or am I looking at problems down the road? If it's a bad approach, what are the alternatives? I've considered opening and closing my main session whenever the user navigates with the grid, but it's not obvious to me how I would do that - hook every event from the grid that could possibly cause a lazy load? I have the nagging feeling that trying to manage my own sessions this way is fundamentally the wrong approach, but it's not obvious what the right one is.

    Read the article

  • value of Identity column returning null when retrieved by value in dataGridView

    - by Raven Dreamer
    Greetings. I'm working on a windows forms application that interacts with a previously created SQL database. Specifically, I'm working on implementing an "UPDATE" query. for (int i = 0; i < dataGridView1.RowCount; i++) { string firstName = (string)dataGridView1.Rows[i].Cells[0].Value; string lastName = (string)dataGridView1.Rows[i].Cells[1].Value; string phoneNo = (string)dataGridView1.Rows[i].Cells[2].Value; short idVal = (short)dataGridView1.Rows[i].Cells[3].Value; this.contactInfoTableAdapter.UpdateQuery(firstName, lastName, phoneNo, idVal); } The dataGridView has 4 columns, First Name, Last Name, Phone Number, and ID (which was created as an identity column when I initially formed the table in SQL). When I try to run this code, the three strings are returned properly, but dataGridView1.Rows[i].Cells[3].Value is returning "null". I'm guessing this is because it was created as an identity column rather than a normal column. What's a better way to retrieve the relevant ID value for my UpdateQuery?

    Read the article

  • Editing list properties using DataGridview

    - by toom
    Ok, I have my custom class: public class FileItem : INotifyPropertyChanged { int id=0; string value=""; public int Id { get { return id; } set { id = value; Changed("Id"); } } public string Value { get { return value; } set { this.value = value; Changed("Value"); } } public event PropertyChangedEventHandler PropertyChanged; void Changed(string name) { if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(name)); } } public BindingList<FileItem> FilesystemEntries = new BindingList<FileItem>(); And I have DatagridView1 with DataSource set to FilesystemEntries: binding.DataSource = FilesystemEntries; Already I can Add and remove rows - these chnages are reflected on collection. However, Value and Id are not saved into bidning list when i change them in DataGridView, id is always 0 and value is "". How can I make this work? Do I need to implement some interface to FileItem to allow editing properties? ReadOnly of DGV is set to false, same to all columns. Editing, Deleting and Changing are enabled.

    Read the article

  • DataGridView: Scroll bar does not refreshed

    - by David.Chu.ca
    I am working (fixing bugs) on a project which was written in VS 2005. There is one DataGridView control on a form. When it is first time loaded, the control's data grid is populated with rows of data from a collection manually or in codes. Actually, there is method PopulateDataGrid() do the job. There is also another control on the form. When control is changed, the data grid will be cleared first and then rows are repopulated again through PopulateDataGrid(). The problem is that when the grid is refreshed, the vertical scroll bar does not get reset correctly. I thought it should be. Since the scroll bar is not reset, when I tried to click on grid and move down, I got exception: the max value of scroll bar was exceeded. All the settings for grid control are default values. For example, the ScrollBars is Both. The following is the only related place to set row auto size property: poDataGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders; I am not sure if there is any property I have to set in designer?

    Read the article

  • Can't get DataGridView to refresh over Linq to SQL (WinForm)

    - by GringoFrenzy
    Very strange situation here: I'm using L2S to populate a DataGridView. Code follows: private void RefreshUserGrid() { var UserQuery = from userRecord in this.DataContext.tblUsers orderby userRecord.DisplayName select userRecord; UsersGridView.DataSource = UserQuery; //I have also tried //this.UserBindingSource.DataSource = UserQuery; //UsersGridView.Datasource = UserBindingSource; UsersGridView.Columns[0].Visible = false; } Whenever I use L2S to Add/Delete records from the database, the GridView refreshes perfectly well. However, if someone is editing the grid and makes a mistake, I want them to be able to hit a refresh button and have their mistakes erased by reloading from the datasource. For the life of me, I can't get it to work. The code I am currently using on my refresh button is this: private void button1_Click(object sender, EventArgs e) { this.DataContext.Refresh(RefreshMode.OverwriteCurrentValues); RefreshUserGrid(); } But the damn GridView remains unaffected. All that happens is the selected row becomes unselected. I have tried .Refresh(), .Invalidate(), I've tried changing the DataSource to NULL and back again (all suggestions from similar posts here)....none of it works. The only time the Grid refreshes is if I restart the app. I must be missing something fundamental, but I'm totally stumped and so are my colleagues. Any ideas? Thanks!

    Read the article

  • How do I obtain selected rows in a DataGridView from different pages

    - by cmrhema
    Hi, I have a windows forms DataGridView, where I have data and a checkbox for each row. I will select check box for a particular row and all the selected rows will be populated in another page. if (grdEmp.Rows.Count > 0) { var selectedEmpIDs= from DataGridViewRow coll in grdEmp.Rows where Convert.ToBoolean(coll.Cells["Select"].Value) == true select coll; if (selectedEmpIDs.Count() > 0) { foreach (DataGridViewRow row in selectedEmpIDs) { selectedEmp+= row.Cells["EmpId"].Value + ","; } } } This works good only for one page. When I navigate to another page, and click the selected rows, the previous one goes off. How do I resolve it. Thanks cmrhema Note :Sorry for the confusion, When I meant it works good for a page, I meant paging. I think I need to add more inputs, There are 10 pages in the gridview. I select the first record from each page of the gridview, one after another by clicking next page( Page next button). But only the record that was selected the last is getting displayed and others and ignored off. What could be the prblm

    Read the article

  • Data confusion - Selecting data in one DataGridView based on selection in another

    - by Logan Young
    This probably isn't the best way to do what I want, but I can't think of anything else to try... NB: I'm using Visual Basic.NET My form has 2 DataGridView controls. One of these is bound to a DataSet, the other isn't visible - at least not until the user selects a uniqueidentifier cell in the 1st grid. When the user makes this selection, the 2nd grid will become visible and display the row from another with the same id as the one selected in the 1st grid. So, basically, I want to dynamically display data in one grid based on user selection in another grid. My code looks like this so far... Private Sub RulesGrid_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles RulesGrid.CellClick Try FlagsGrid.Visible = True ''// MsgBox(RulesGrid.CurrentCell.Value.ToString()) Dim sql As String = "SELECT * FROM ctblMKA_Status_Flags " + _ "WHERE intStatusID = '" & RulesGrid.CurrentCell.Value & "'" DSFlags = GetDS(sql) DSFlags.DataSetName = "FlagsDataSet" FlagsGrid.DataSource = DSFlags ProgressBar.Visible = False Catch ex As Exception MsgBox(ex.ToString) End Try End Sub I feel like I'm missing something here... Any ideas anyone?

    Read the article

  • Adding rows to a data-bound DataGridView [Winforms]

    - by Mishko
    I want to bind a table from a database to a DataGridView, but I want to also add one more row with a sum of the values in the columns with indexes 3,4,7,8,9... How can I do that? Thanks! DataTable table1 = new DataTable(); double brutoUkupno1 = 0; double porezUkupno1 = 0; double doprinosUkupno1 = 0; double netoUkupno1 = 0; double doprinosTeretUkupno1 = 0; double topliObrokUkupno1 = 0; double regresUkupno1 = 0; Connection con = new Connection(); table1 = con.boundTable(month, Convert.ToInt32(year)); //This is method which returns DataTable table1.Rows.Add(null, null, null, null, null, null, null, null, null, null, null, null, null, null); table1.Rows.Add(null, null, null, null, null, null, null, null, null, null, null, null, null, null); dgv2.Visible = true; dgv2.DataSource = table1; for (int i = 0; i < dgv2.RowCount - 2; i++) { topliObrokUkupno1 += Convert.ToDouble(dgv2.Rows[i].Cells[7].Value); regresUkupno1 += Convert.ToDouble(dgv2.Rows[i].Cells[8].Value); brutoUkupno1 += Convert.ToDouble(dgv2.Rows[i].Cells[9].Value); porezUkupno1 += Convert.ToDouble(dgv2.Rows[i].Cells[10].Value); doprinosUkupno1 += Convert.ToDouble(dgv2.Rows[i].Cells[11].Value); netoUkupno1 += Convert.ToDouble(dgv2.Rows[i].Cells[12].Value); doprinosTeretUkupno1 += Convert.ToDouble(dgv2.Rows[i].Cells[13].Value); //Now I am having problems with this below, putting things above to dgv2 : } dgv2.Rows[dgv2.Rows.Count - 1].Cells[0].Value = "Ukupno"; dgv2.Rows[dgv2.Rows.Count - 1].Cells[3].Value = month.ToString(); dgv2.Rows[dgv2.Rows.Count - 1].Cells[4].Value = year.ToString(); dgv2.Rows[dgv2.Rows.Count - 1].Cells[7].Value = topliObrokUkupno1.ToString(); dgv2.Rows[dgv2.Rows.Count - 1].Cells[8].Value = regresUkupno1.ToString(); dgv2.Rows[dgv2.Rows.Count - 1].Cells[9].Value = brutoUkupno1.ToString(); dgv2.Rows[dgv2.Rows.Count - 1].Cells[10].Value = porezUkupno1.ToString(); dgv2.Rows[dgv2.Rows.Count - 1].Cells[11].Value = doprinosUkupno1.ToString(); dgv2.Rows[dgv2.Rows.Count - 1].Cells[12].Value = netoUkupno1.ToString(); dgv2.Rows[dgv2.Rows.Count - 1].Cells[13].Value = doprinosTeretUkupno1.ToString(); dgv2.Rows[dgv2.RowCount - 2].Height = 3; dgv2.Rows[dgv2.RowCount - 2].DefaultCellStyle.BackColor = Color.Black;

    Read the article

  • Bound DataGridView not updating data source

    - by Max Yaffe
    I'm trying to bind a table of structures to a DataGridView. Loading and viewing the table is working fine but I can't edit a value and get it stored back into the table. Here's what I'm doing. I have a "primitive" data type, Real defined by public struct MyReal:IMyPrimative { public Double m_Real; //... public MyReal(String val) { m_Real = default(Double); Init(val); } //... } It gets used in a structure: public struct MyReal_Record : IMyRecord { public MyReal Freq { get; set;} MyReal_Record(String[] vals) { Init(vals); } } And the structure is used to define a table using a generic Binding List public class MyTable<S> : BindingList<S> where S: struct, IMyRecord { public Type typeofS; public MyTable() { typeofS = typeof(S); // ... } This table is used as a binding source for a grid, dynamically. private void miLoadFile_Click(object sender, EventArgs e) { MyModel.Table<Real_Record> RTable = new MyModel.Table<Real_Record>(); //... Table initialized here //set up grid with virtual mode dataGridView1.DataSource = RTable; } All of this works fine and I can create RTable, initialize it and display it in a grid. The grid allows editing and has events set for CellParsing and CellFormatting which look like: private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (e.DesiredType != typeof(String)) return; e.Value = e.Value.ToString(); } private void dataGridView1_CellParsing(object sender, DataGridViewCellParsingEventArgs e) { if (e.DesiredType != typeof(MyReal)) return; e.Value = new MyReal(e.Value.ToString()); e.ParsingApplied = true; this.dataGridView1.UpdateCellValue(e.ColumnIndex, e.RowIndex); } When I edit a value in a cell, I can change the text. On leaving the cell, CellParsing fires and the event handler is called. Everything seems to be correct going into the CellParsing handler. e.DesiredType is MyReal. e.Value is a string with the new value. After the new MyReal is created from the string, e.Value is set correctly. RowIndex and ColumnIndex are correct. ReadOnly is set false. However, when I leave the cell, the system restores the original value to the cell. I thought the UpdateCellValue would replace the value in the dataSource but I seem to be missing something. What did I miss? Thanks, Max

    Read the article

  • DataGridView validating old value insted of new value.

    - by Scott Chamberlain
    I have a DataGridView that is bound to a DataTable, it has a column that is a double and the values need to be between 0 and 1. Here is my code private void dgvImpRDP_InfinityRDPLogin_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { if (e.ColumnIndex == dtxtPercentageOfUsersAllowed.Index) { double percentage; if(dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, e.RowIndex].Value.GetType() == typeof(double)) percentage = (double)dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, e.RowIndex].Value; else if (!double.TryParse(dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, e.RowIndex].Value.ToString(), out percentage)) { e.Cancel = true; dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, e.RowIndex].ErrorText = "The value must be between 0 and 1"; return; } if (percentage < 0 || percentage > 1) { e.Cancel = true; dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, e.RowIndex].ErrorText = "The value must be between 0 and 1"; } } } However my issue when dgvImpRDP_InfinityRDPLogin_CellValidating fires dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, e.RowIndex].Value will contain the old value before the edit, not the new value. For example lets say the old value was .1 and I enter 3. The above code runs when you exit the cell and dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, e.RowIndex].Value will be .1 for that run, the code validates and writes 3 the data to the DataTable. I click on it a second time, try to leave, and this time it behaves like it should, it raises the error icon for the cell and prevents me from leaving. I try to enter the correct value (say .7) but the the Value will still be 3 and there is now no way out of the cell because it is locked due to the error and my validation code will never push the new value. Any recommendations would be greatly appreciated. EDIT -- New version of the code based off of Stuart's suggestion and mimicking the style the MSDN article uses. Still behaves the same. private void dgvImpRDP_InfinityRDPLogin_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { if (e.ColumnIndex == dtxtPercentageOfUsersAllowed.Index) { dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, e.RowIndex].ErrorText = String.Empty; double percentage; if (!double.TryParse(dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, e.RowIndex].FormattedValue.ToString(), out percentage) || percentage < 0 || percentage > 1) { e.Cancel = true; dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, e.RowIndex].ErrorText = "The value must be between 0 and 1"; return; } } }

    Read the article

  • How can you determine when the user scrolls to the bottom of a DataGridView?

    - by Craig
    I am writing a C# Windows Forms Application in Visual Studio 2008. I have a DataGridView with a lot of data in it. I would like to initially only populate 10,000 rows and add more only when the user scrolls to the bottom. I am handling the DataGridView's Scroll event, but it never seems to raise with the ScrollEventArgs.Type property set to Last, which is the condition I think I need to catch to add more rows. I have read about people having bad experiences with the DataGridView.Scroll event (e.g. http://stackoverflow.com/questions/785200/datagridview-scroll-event-and-scrolleventtype-endscroll), but the solution provided (http://stackoverflow.com/questions/472389/how-can-i-receive-the-scroll-box-type-scroll-events-from-a-datagridview/767603#767603) only adds the ScrollEventArgs.Type property to come back as EndScroll, not Last like I need. Does anybody know how to get the event to raise properly, or another way to accomplish this task?

    Read the article

  • DataGridView CheckBox events

    - by Kevin
    I'm making a DataGridView with a series of Checkboxes in it with the same labels horizontally and vertically. Any labels that are the same, the checkboxes will be inactive, and I only want one of the two "checks" for each combination to be valid. The following screenshot shows what I have: Anything that's checked on the lower half, I want UN-checked on the upper. So if [quux, spam] (or [7, 8] for zero-based co-ordinates) is checked, I want [spam, quux] ([8, 7]) un-checked. What I have so far is the following: dgvSysGrid.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders; dgvSysGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; string[] allsysNames = { "heya", "there", "lots", "of", "names", "foo", "bar", "quux", "spam", "eggs", "bacon" }; // Add a column for each entry, and a row for each entry, and mark the "diagonals" as readonly for (int i = 0; i < allsysNames.Length; i++) { dgvSysGrid.Columns.Add(new DataGridViewCheckBoxColumn(false)); dgvSysGrid.Columns[i].HeaderText = allsysNames[i]; dgvSysGrid.Rows.Add(); dgvSysGrid.Rows[i].HeaderCell.Value = allsysNames[i]; // Mark all of the "diagonals" as unable to change DataGridViewCell curDiagonal = dgvSysGrid[i, i]; curDiagonal.ReadOnly = true; curDiagonal.Style.BackColor = Color.Black; curDiagonal.Style.ForeColor = Color.Black; } // Hook up the event handler so that we can change the "corresponding" checkboxes as needed //dgvSysGrid.CurrentCellDirtyStateChanged += new EventHandler(dgvSysGrid_CurrentCellDirtyStateChanged); dgvSysGrid.CellValueChanged += new DataGridViewCellEventHandler(dgvSysGrid_CellValueChanged); } void dgvSysGrid_CellValueChanged(object sender, DataGridViewCellEventArgs e) { Point cur = new Point(e.ColumnIndex, e.RowIndex); // Change the diagonal checkbox to the opposite state DataGridViewCheckBoxCell curCell = (DataGridViewCheckBoxCell)dgvSysGrid[cur.X, cur.Y]; DataGridViewCheckBoxCell diagCell = (DataGridViewCheckBoxCell)dgvSysGrid[cur.Y, cur.X]; if ((bool)(curCell.Value) == true) { diagCell.Value = false; } else { diagCell.Value = true; } } /// <summary> /// Change the corresponding checkbox to the opposite state of the current one /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void dgvSysGrid_CurrentCellDirtyStateChanged(object sender, EventArgs e) { Point cur = dgvSysGrid.CurrentCellAddress; // Change the diagonal checkbox to the opposite state DataGridViewCheckBoxCell curCell = (DataGridViewCheckBoxCell)dgvSysGrid[cur.X, cur.Y]; DataGridViewCheckBoxCell diagCell = (DataGridViewCheckBoxCell)dgvSysGrid[cur.Y, cur.X]; if ((bool)(curCell.Value) == true) { diagCell.Value = false; } else { diagCell.Value = true; } } The problem comes is that the cell value changed always seems to be "one behind" where you actually click if I use the CellValueChanged event, and I'm not sure how to get the current cell if I'm in the "dirty" state as curCell comes in as a null (suggesting the current cell address is wrong somehow, but I didn't try and get that value out) meaning that path isn't working at all. Basically, how do I get the "right" address with the right boolean value so that my flipping algorithm will work?

    Read the article

  • fill combobox value in datagridview based on other combobox in datagridview

    - by Purohit Raghu
    I m creating Web Application..in C# I have One Data grid view In that i Have 2 Combo box i m trying 2 bind second combo box based on first combo-box. in First Combo-box I have value Shirt,T shirt so i want if shirt is selected than second combo-box should have value Slim,Regular..and if T shirt Is selected than second Combo-box should have V neck and rounded color. i have different table for thirst and shirt type... I work fine for first time but when i goes on second row and change the combo box value than it will also change value of second combo box value of previous row as well .. Where i need to change to prevent change in upper row i have following code private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { if (dataGridView1.CurrentCell.ColumnIndex == 0) { ComboBox cbx = e.Control as ComboBox; cbx.SelectionChangeCommitted -= new EventHandler(cbx_SelectionChangeCommitted); cbx.SelectionChangeCommitted += new EventHandler(cbx_SelectionChangeCommitted); } } private void cbx_SelectionChangeCommitted(object sender, EventArgs e) { int selectedIndex = ((ComboBox)sender).SelectedIndex; if (selectedIndex == 1) //this condition is true if i have selected shirt from combobox1 { ShirtType(); } if (selectedIndex == 2) { Tshirtype(); } } void ShirtType() { try { string str; str = "select ShirtType_name,ShirtType_Id from ShirtType_master"; ds = new DataSet(); ds = cn.readdata(str); Type.DataSource = ds.Tables[0];//Type is Combobox name of Second Combobox Type.DisplayMember = ds.Tables[0].Columns[0].ToString(); ; Type.ValueMember = ds.Tables[0].Columns[1].ToString(); ; } catch (Exception ee) { } } void Tshirtype() { try { string str; str = "select TShirtType_name,TshirtType_Id from TshirtType_Master"; ds = new DataSet(); ds = cn.readdata(str); Type.DataSource = ds.Tables[0]; Type.DisplayMember = ds.Tables[0].Columns[0].ToString(); ; Type.ValueMember = ds.Tables[0].Columns[1].ToString(); ; }

    Read the article

  • How do you keep the text selection on a DataGridView?

    - by fneep
    I'm running C# 2.0, and I've written an application with a DataGridView in virtualmode and a TreeView in the same form, but in different panels of a SplitContainer. My application has a "find all" function that finds all instances of a certain string, and adds them as the child nodes to a new node to the TreeView (it's a tree view because you can have multiple search results by having different root nodes). That idea is that when you click on one of those search results in the TreeView, that it would select the specific text of that result in the DataGridView (Virtually the same as Notepad++'s find all function) When I click on the TreeView, it does set the selected cell of the DataGridView and highlight the specific text, but it loses that specific text selection instantly (but keeps the cell selection) because by clicking on the TreeView the DataGridView loses focus. Here's the code for the AfterSelect of the TreeView: private void Tree_Results_AfterSelect(object sender, TreeViewEventArgs e) { if (e.Node.Level > 0) { SearchResult SelectedItem = (SearchResult)Tree_Results.SelectedNode.Tag; DataViewMain.CurrentCell = DataViewMain[SelectedItem.TypeIndex, SelectedItem.LineIndex]; DataViewMain.BeginEdit(false); DataGridViewTextBoxEditingControl SelectionData = (DataGridViewTextBoxEditingControl)DataViewMain.EditingControl; SelectionData.SelectionStart = SelectedItem.HighlightStart; SelectionData.SelectionLength = SelectedItem.HightlightLength; } } If the DataGridView were a text box I could possibly set HideSelection to false, but DataGridViews have no such property (and changing the Hide Selection for the EditingControl does nothing) Any ideas? I'm receptive to a different control instead of a TreeView that would allow my DataGridView to retain focus.

    Read the article

  • Could not determine metatable error binding list to asp.net datagridview

    - by Scott Vercuski
    I am working with the following block of code ... List<ThemeObject> themeList = (from theme in database.Themes join image in database.DBImages on theme.imageID equals image.imageID into resultSet from item in resultSet select new ThemeObject { Name = theme.Name, ImageID = item.imageID}).ToList(); dgvGridView.DataSource = themeList; dgvGridView.DataBind(); The list object populates fine. The datagrid is setup with 2 columns. A textbox column for the "Name" which is bound to "Name" An image column which is bound to the "ImageID" field When I execute the code I receive the following error on the DataBind() Could not determine a MetaTable. A MetaTable could not be determined for the data source '' and one could not be inferred from the request URL. Make sure that the table is mapped to the dats source, or that the data source is configured with a valid context type and table name, or that the request is part of a registered DynamicDataRoute. I'm not using any dynamicdataroutes as far as I can tell. Has anyone experienced this error before?

    Read the article

  • Why is a DataGridView so row-centric.

    - by Spike
    Why is there a DataGridViewRow.Cells property, but not a DataGridViewColumn.Cells property? What's so important about rows that I'll never want to iterate down a column? I'm not saying that it makes it particularly difficult to do or anything, it just strikes me as oddly asymmetrical. I'm implementing a "fill down" type behaviour, and it'd be handy is all.

    Read the article

  • DataGridView's SelectionChange event firing twice on DataBinding even after removing event binding

    - by Shantanu Gupta
    This Code triggers selection change event twice. how can I prevent it ? Currently i m using a flag or focused property to prevent this. But what is the actual way ? I am using it on winfoms EDIT My Mistake in writing Question, here is the correct code that i wanted to ask private void frmGuestInfo_Load(object sender, EventArgs e) { this.dgvGuestInfo.SelectionChanged -= new System.EventHandler(this.dgvGuestInfo_SelectionChanged); dgvGuestInfo.DataSource=dsFillControls.Tables["tblName"]; this.dgvGuestInfo.SelectionChanged += new System.EventHandler(this.dgvGuestInfo_SelectionChanged); } private void dgvGuestInfo_SelectionChanged(object sender, EventArgs e) { //this function is raised twice, i was expecting that this will not be raised }

    Read the article

  • Updating DataGridView from another Form using BackGroundWorker

    - by FezKazi
    Hi! I Have one Form (LoginForm) which has a Background Worker Monitoring a database for new entries. Then I have another Form (AdminForm) which I need to signal to update its datagrids whenever new data is available. I could poll the database in the AdminForm too, but considering that LoginForm is already doing some polling, which can be costly, I just want to signal AdminForm to update the DataGridViews with the new data. You may ask, why is LoginForm doing the polling when youre showing the stuff in the AdminForm? Well, LoginForm is actually processing the data and sending it over the Serial Port :$ heheh. I want it to be able to process the data without having an administrator logged in all the time.

    Read the article

< Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >