Click here to Skip to main content
15,887,135 members
Home / Discussions / C#
   

C#

 
GeneralRe: Anonymous delegates Pin
RugbyLeague17-Aug-10 5:04
RugbyLeague17-Aug-10 5:04 
GeneralRe: Anonymous delegates Pin
OriginalGriff17-Aug-10 6:20
mveOriginalGriff17-Aug-10 6:20 
JokeRe: Anonymous delegates Pin
Not Active17-Aug-10 6:30
mentorNot Active17-Aug-10 6:30 
GeneralRe: Anonymous delegates Pin
Yusuf17-Aug-10 13:09
Yusuf17-Aug-10 13:09 
GeneralRe: Anonymous delegates Pin
RugbyLeague17-Aug-10 12:17
RugbyLeague17-Aug-10 12:17 
AnswerRe: Anonymous delegates Pin
AspDotNetDev17-Aug-10 12:57
protectorAspDotNetDev17-Aug-10 12:57 
GeneralRe: Anonymous delegates Pin
RugbyLeague17-Aug-10 21:31
RugbyLeague17-Aug-10 21:31 
QuestionRebinding DGV Combobox Column. C#.Net 2008, Framework 3.5. Pin
priyamtheone17-Aug-10 2:52
priyamtheone17-Aug-10 2:52 
I have a dgv that's bound to a table tblQuoteItems.
One of the columns of the dgv is ItemID which is a combobox column.
Its value is obtained from ItemID field of tblQuoteItems.
Before binding the dgv, the ItemID column is populated from
tblItems table containing fields ItemID and Item.
The ItemID column of the dgv has ItemID as valuemember and Item as
displaymember.
Now is it possible to rebind only the ItemID column while keeping the
dgv state intact i.e. without rebinding the dgv?
For example I open up a lookup form and modify tblItems table,
then I want the effect to be acted upon the ItemID column of the dgv
without affecting the state of the dgv.
I recalled BindDGVComboBox method defined underneath after modifying
the values of tblItems but of no avail. Please help.

My code follows:

SqlConnection con;
string strSql;
SqlDataAdapter da;
DataTable dt;
SqlCommandBuilder cb;
BindingSource bs = null;

void PopulateDgv()
{
    LineID = new DataGridViewTextBoxColumn();
    QuoteID = new DataGridViewTextBoxColumn();
    ItemID = new DataGridViewComboBoxColumn();
    LookupItems = new DataGridViewButtonColumn();
    Quantity = new DataGridViewTextBoxColumn();
    UnitPrice = new DataGridViewTextBoxColumn();
    LineTotal = new DataGridViewTextBoxColumn();

    dgvItems.Columns.Clear();
    dgvItems.DataSource = null;
    dgvItems.Columns.AddRange(new DataGridViewColumn[] {LineID, QuoteID, ItemID, LookupItems, Quantity, UnitPrice, LineTotal });
    LineID.Name = "LineID";
    LineID.DataPropertyName = "LineID";
    LineID.Visible = false;
    QuoteID.Name = "QuoteID";
    QuoteID.DataPropertyName = "QuoteID";
    QuoteID.Visible = false;
    ItemID.Name = "ItemID";
    ItemID.DataPropertyName = "ItemID";
    LookupItems.Name = "LookupItems";
    LookupItems.DataPropertyName = "LookupItems";
    LookupItems.DefaultCellStyle.NullValue = "...";
    LookupItems.Resizable = DataGridViewTriState.False;
    Quantity.Name = "Quantity";
    Quantity.DataPropertyName = "Quantity";
    UnitPrice.Name = "UnitPrice";
    UnitPrice.DataPropertyName = "UnitPrice";
    LineTotal.Name = "LineTotal";
    LineTotal.DataPropertyName = "LineTotal";
    LineTotal.ReadOnly = true;

    BindDGVComboBox(ItemID, "Select ItemID,Item From tblShopItems Order By ItemID", "ItemID", "Item");

    if (bs == null) { bs = new BindingSource(); }
    if (dt == null) { dt = new DataTable(); }
    strSql = "Select LineID,QuoteID,ItemID,'...' As LookupItems,Quantity,UnitPrice,LineTotal From tblShopQuotesItems Where QuoteID=" + Globals.Val(Tag);
    da = CreateDataAdapter(strSql);
    cb = new SqlCommandBuilder(da);
    dt.Locale = System.Globalization.CultureInfo.InvariantCulture;
    dt.Clear();
    da.Fill(dt);
    bs.DataSource = dt;
    dgvItems.DataSource = bs;
}

void BindDGVComboBox(DataGridViewComboBoxColumn objComboBox, string strQuery, string strValueMember, string strDisplayMember)
{
    DataSet ds = new DataSet();

    ds = CreateDataSet(strQuery);
    DataView dv = ds.Tables["dtDataTable"].DefaultView;
    objComboBox.DataSource = null;
    objComboBox.DataSource = dv;
    if (strValueMember != null) { objComboBox.ValueMember = strValueMember; }
    objComboBox.DisplayMember = strDisplayMember;
}

DataSet CreateDataSet(string strQuery)
{
    DataSet ds = new DataSet();
    SqlDataAdapter da = CreateDataAdapter(strQuery);
    SqlCommandBuilder cb = new SqlCommandBuilder(da);
    da.Fill(ds, "dtDataTable");
    return ds;
}

SqlDataAdapter CreateDataAdapter(string strQuery)
{
    SetConnection();
    SqlDataAdapter daAdapter = new SqlDataAdapter(strQuery, con);
    CloseConnection();
    return daAdapter;
}

void SetConnection()
{
    if (con == null) { con = new SqlConnection(GetConnectionString()); }
    if (con.State == ConnectionState.Closed) { con.Open(); }
}

string GetConnectionString()
{
    string strConn;
    strConn = "Persist Security Info=False;User ID=sa;Password=;Initial Catalog=TestDB;Data Source=MyServer";
    return strConn;
}

QuestionSql server Login details Pin
ksss_maheshece17-Aug-10 1:15
ksss_maheshece17-Aug-10 1:15 
AnswerRe: Sql server Login details Pin
Not Active17-Aug-10 2:07
mentorNot Active17-Aug-10 2:07 
GeneralRe: Sql server Login details Pin
ksss_maheshece17-Aug-10 2:15
ksss_maheshece17-Aug-10 2:15 
GeneralRe: Sql server Login details Pin
Not Active17-Aug-10 2:26
mentorNot Active17-Aug-10 2:26 
GeneralRe: Sql server Login details Pin
Dave Kreskowiak17-Aug-10 3:45
mveDave Kreskowiak17-Aug-10 3:45 
GeneralRe: Sql server Login details Pin
Eddy Vluggen17-Aug-10 9:43
professionalEddy Vluggen17-Aug-10 9:43 
Questiondetect border into user control Pin
billy_iii17-Aug-10 1:09
billy_iii17-Aug-10 1:09 
AnswerRe: detect border into user control Pin
R. Giskard Reventlov17-Aug-10 1:13
R. Giskard Reventlov17-Aug-10 1:13 
GeneralRe: detect border into user control Pin
billy_iii17-Aug-10 1:33
billy_iii17-Aug-10 1:33 
AnswerRe: detect border into user control PinPopular
Luc Pattyn17-Aug-10 1:52
sitebuilderLuc Pattyn17-Aug-10 1:52 
AnswerRe: detect border into user control Pin
AspDotNetDev17-Aug-10 13:26
protectorAspDotNetDev17-Aug-10 13:26 
Questionretrieving text from word file Pin
annie_bel17-Aug-10 0:26
annie_bel17-Aug-10 0:26 
AnswerRe: retrieving text from word file Pin
Richard MacCutchan17-Aug-10 0:47
mveRichard MacCutchan17-Aug-10 0:47 
AnswerRe: retrieving text from word file Pin
R. Giskard Reventlov17-Aug-10 0:47
R. Giskard Reventlov17-Aug-10 0:47 
QuestionCan't see the exception of the code Pin
Yanshof16-Aug-10 21:22
Yanshof16-Aug-10 21:22 
AnswerRe: Can't see the exception of the code Pin
R. Giskard Reventlov16-Aug-10 21:38
R. Giskard Reventlov16-Aug-10 21:38 
GeneralRe: Can't see the exception of the code Pin
Yanshof16-Aug-10 21:43
Yanshof16-Aug-10 21:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.