473,948 Members | 19,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# windows Assign a value to DataGridViewCom boBox cell based on another row

Plater
7,872 Recognized Expert Expert
I feel like this question has been asked before, but I couldn't find it.
I think I am missing something obvious.

Basically I am going to have a DataGridView with two columns. One textbox, one combobox.
The textbox column is going to be coming from a database (actually I could manually create it if i had to). It makes about 20 rows, each with a unique value for the textbox column.
The available choices for the combobox row are coming from a list (I apply it as a datasource currently, it might be better if I manually add the items?)

So for each entry, you can pick a value from a combox, pretty simple, that part works.

Now what I want is, based on some criteria, that a certain value in the combobox field be "selected" by start, instead of an empty box.

I am roughly going to take a particular string, and if its a choice in the combobox, select it. If it is NOT a choice, select the first item in the combobox.

I cannot seem to set the combobox value. With a regular combobox, there is a .Contains on the items (items is always empty when using a datasource) and then is has a .SelectedItem property. The Selected whatever properties aren't on thse DataGridViewCom boBox cells.

I have tried just setting the .Value property of the cell, which correctly triggers the DataError event if it's not a choice, but then the value cannot be re-set based on that?


EDIT: I attached a picture of desired output. I can correctly set the values (using the Items.Contains( )) now, but it only actually sets the value if I have "looked" at the DataGridView first (its on another tab)
Attached Images
File Type: jpg desiredlayout.JPG (14.5 KB, 521 views)
Oct 30 '08 #1
1 4529
Plater
7,872 Recognized Expert Expert
What I ended up doing was putting it all on the main tab...and hoping it doesn't cause anymore issues
Oct 31 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1891
by: Dominik Luyten | last post by:
Hi, I would like to format certain DataRows in a Windows.Forms.DataGrid. I know how to do that for the columns, but I cannot find a way to assign a specific font, color etc. to a specific kind of DataRows. I have 4 different kinds identified by a type value and would like to show the Rows with different styles For Example: All Rows of type 1 should be in bold All Rows of type 2 should be in italics and grey
3
2455
by: Richard | last post by:
I'm trying to change a value of a cell based on another before the grid is displayed. I'm using the ItemDataBound event like this for a simple test: Select Case e.Item.ItemType Case ListItemType.Item, ListItemType.AlternatingItem If e.Item.Cells(7).Text = String.Empty Then e.Item.Cells(7).Text = "hello" End If End Select
3
7505
by: Chris Paul | last post by:
I'm having trouble with PHP & PostgreSQL/OpenLDAP/Apache on Windows. I've set this up countless times on BSD (piece of cake) but I'm trying to do this on Windows now so that my developer can work on her local machine. Everything looks pretty good. OpenLDAP/cygwin works great. PostgreSQL works great. Apache runs. PHP runs. But when I try to connect to my PostgreSQL server using PHPPgAdmin, I
6
2814
by: Andrew Robinson | last post by:
assuming that I have a class public class MyClass { public string FirstName { get {...} set {...} } } how can I assign the FirstName property using reflection on a generic class
0
1111
by: alwayssmiling | last post by:
Hi All, In my class im reading each and every cell with the help of indexes like .... . From this im reading the Color value of that cell. Now i want to assign this color value to some other property which looks like public color setcolor { get { return m_Color; }
5
1534
by: Ronald S. Cook | last post by:
I need ideas on how to best design a Windows form for my particular situation. On a cattle feeding yard there will be between about 300 and 600 pens. On my "Pen Feeding Sequence" form, I want the user to be able to setup and maintain the order in which the pens should be fed (ultimately in the Pen table is a column named Sequence that gets an interger value). So on the form...
5
8097
by: howa | last post by:
Hi, Consider a simple example, e.g. var a = { 'a': 'b', 'c': 'd' }
0
1172
by: dan | last post by:
Hi, I have a GridView with five columns. One of the column renders its content either as a FileUpload or TextBox - depending on a value in another cell. I created an EditItemTemplate for the column and placed both controls in it. The controls' Visible property is initially set to false for both of them. Based on a value of another field I'd like to be able to set Visible property to true for one of the controls. Could someone please...
2
14799
by: =?Utf-8?B?RHJEQkY=?= | last post by:
I understand that the Value put into a DataGridViewComboBoxCell has to be a member of the Items list or an exception is thrown. I also understand that you can override that exception by handling the DataError event and just doing nothing in the circumstance that caused the error. Here's my situation: I would like to allow the user to EITHER select an item from the ComboBox (in a DataGridView) OR type in a new value of their own.
0
10165
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9988
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11580
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11179
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9898
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7431
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6119
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4541
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.