المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Problem with data GridView C#



C# Programming
06-16-2009, 11:50 AM
Hi,
First time I am using datagridview I have some questions and problems.
Please guide me or provide solutions if possible.

I am using adapter to bind the DGV.

1. My datasource is coming through multiple tables
Exe: select a,b,c,d from t1 left outer join t2 on t1.a=t2.d
Because of that any kind of modification update, delete, insert not working
2. unable to add auto row columns
3. unable to find cells textbox property, I want to use cells textbox autocomplete property for providing help to users
private void dgCountryZone_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (dgCountryZone.Columns[this.dgCountryZone.CurrentCell.ColumnIndex].Name.Equals("Destination Code"))
{
TextBox txt = e.Control as TextBox;
txt.Multiline = false;
txt.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
txt.AutoCompleteSource = AutoCompleteSource.CustomSource;
txt.AutoCompleteCustomSource = colCountryListCodeCheck;
}
}

4. in the time of validation if I am using cells current position its not work
exe: say present cell position is cell(4,5) now user press tab if validate pass then I want to set focus on cell(4,9) or else in cell(4,5) but it moves on cell(4,10) or cell(4,6)

private void dgCountryZone_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
Int32 RowCounter;
Int32 DuplicateCounter;
IDataReader idrCountryName;
DuplicateCounter = 0;

if (dgCountryZone.Columns[e.ColumnIndex].Name == "Destination Code")
{
if (Convert.ToString(dgCountryZone.Rows[e.RowIndex].Cells[e.ColumnIndex].Value) != "")
{
for (RowCounter = 0; RowCounter 1)
{
dgCountryZone.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = "";
MessageBox.Show(MessageResource.DuplicateRecord, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
dgCountryZone.CurrentCell = dgCountryZone[e.ColumnIndex, e.RowIndex];
return;
}
else
{
DataAccessLayer daobj = new DataAccessLayer();
UserDataType.CountryParam CParam = new UserDataType.CountryParam();
CParam.szCountryCode = Convert.ToString(dgCountryZone.Rows[e.RowIndex].Cells[e.ColumnIndex].Value);
dgCountryZone.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].Value = "";
idrCountryName = daobj.GetHelpCountryName(CParam);
while (idrCountryName.Read())
dgCountryZone.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].Value = idrCountryName.GetString(0);
if (Convert.ToString(dgCountryZone.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].Value) != "")
{
dgCountryZone.CurrentCell = dgCountryZone[e.ColumnIndex + 1, e.RowIndex];
return;
}
else
{
MessageBox.Show(MessageResource.CodeNotFound, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
dgCountryZone.CurrentCell = dgCountryZone[e.ColumnIndex, e.RowIndex];
return;
}
}
}
else
{
MessageBox.Show(MessageResource.BlankField, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
dgCountryZone.CurrentCell = dgCountryZone[e.ColumnIndex, e.RowIndex];
return;
}
}
if (dgCountryZone.Columns[e.ColumnIndex].Name == "Per CWB/KG")
{
if (Convert.ToString(dgCountryZone.Rows[e.RowIndex].Cells[e.ColumnIndex].Value) != "")
{
if (Convert.ToString(dgCountryZone.Rows[e.RowIndex].Cells[e.ColumnIndex].Value).ToUpper() != "K" && Convert.ToString(dgCountryZone.Rows[e.RowIndex].Cells[e.ColumnIndex].Value).ToUpper() != "W")
{
MessageBox.Show("Please select [W for per CWB] and [K for KG]", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
dgCountryZone.CurrentCell = dgCountryZone[e.ColumnIndex, e.RowIndex];
return;
}
}
else
{
MessageBox.Show(MessageResource.BlankField, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
dgCountryZone.CurrentCell = dgCountryZone[e.ColumnIndex, e.RowIndex];
return;
}
}
}

Please suggest if I am wrong or any code help if possible

Regards
Prakash

Prakash